Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
# Ignore the build directory for all projects
**/target/

# Ignore the lock file (Optional: recommended for libraries,
# but usually kept for final applications/binaries)
# **/Cargo.lock

# IDE specific files
.vscode/
.idea/
**/*.rs.bk
# mac os
.DS_Store
141 changes: 0 additions & 141 deletions Cargo.lock

This file was deleted.

6 changes: 0 additions & 6 deletions Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Hellow ( •̀ ω •́ )y

This is just me practicing rust
his is just me practicing zig ^-^
37 changes: 37 additions & 0 deletions functions.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const std = @import("std");

pub fn main() !void {
const stdin = std.io.getStdIn().reader();
const stdout = std.io.getStdOut();

try stdout.writeAll("enter temp: ");

// fixed size, so its on the stack
var buf: [1024]u8 = undefined;

// reads from stdin until delimeter encountered
// i.e. enter is pressed
//
// |line| is a payload capture that unwraps the returned optional,
// as the user could have entered no data (e.g. EOF)
if (try stdin.readUntilDelimiterOrEof(&buf, '\n')) |line| {
// {s} specifies line as a string
// std.debug.print("user entered: {s}\n", .{line});

if (std.fmt.parseFloat(f32, line)) |value| {
// {d} specifies decimal
// std.debug.print("float is: {d}\n", .{value});

convert(value);
} else |err| {
std.debug.print("please enter a valid float: {}\n", .{err});
}
} else {
std.debug.print("please enter a valid float\n", .{});
}
}

fn convert(input: f32) void {
const result = input * 1.8 + 32.0;
std.debug.print("{d}°F\n", .{result});
}
41 changes: 41 additions & 0 deletions guess_the_number.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const std = @import("std");

pub fn main() !void {
const stdin = std.io.getStdIn().reader();
const secret_number = try random(1, 100);
var buf: [1024]u8 = undefined;

while (true) {
try std.debug.print("guess the number (1 - 100): ", .{});

if (try stdin.readUntilDelimiterOrEof(&buf, '\n')) |line| {
// parse base 10 integer
if (std.fmt.parseInt(u8, line, 10)) |guess| {
std.debug.print("you guessed {d}\n", .{guess});

switch (std.math.order(guess, secret_number)) {
.lt => std.debug.print("too small\n", .{}),
.gt => std.debug.print("too large\n", .{}),
.eq => {
std.debug.print("you win!\n", .{});
break;
},
}
} else |err| {
std.debug.print("please enter a valid integer: {}\n", .{err});
}
} else {
std.debug.print("failed to read line", .{});
}
}
}

fn random(min: u8, max: u8) !u8 {
var seed: u64 = undefined;
try std.posix.getrandom(std.mem.asBytes(&seed));

var prng: std.Random.DefaultPrng = .init(seed);
const rand = prng.random();

return rand.intRangeAtMost(u8, min, max);
}
5 changes: 5 additions & 0 deletions hello-world.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const std = @import("std");

pub fn main() void {
std.debug.print("Hello, world!\n", .{});
}
6 changes: 0 additions & 6 deletions projects/chp3/Cargo.toml

This file was deleted.

28 changes: 0 additions & 28 deletions projects/chp3/src/main.rs

This file was deleted.

6 changes: 0 additions & 6 deletions projects/functions/Cargo.toml

This file was deleted.

24 changes: 0 additions & 24 deletions projects/functions/src/main.rs

This file was deleted.

Loading