Skip to content

Instantly share code, notes, and snippets.

@tatimblin
Created October 6, 2023 06:21
Show Gist options
  • Save tatimblin/398584bb7a83e9d95ceabf905c5c4ffd to your computer and use it in GitHub Desktop.
Save tatimblin/398584bb7a83e9d95ceabf905c5c4ffd to your computer and use it in GitHub Desktop.
Trying out the zig programming language.
pub fn main() !void {
var buffer: [100]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&buffer);
const allocator = fba.allocator();
var seen: [26]bool = undefined;
var seenCount: u8 = 0;
var i: usize = 0;
while (i < seen.len) : (i += 1) {
seen[i] = false;
}
const str = "the quick fox";
for (str) |char| {
var keycode = try getKeycode(allocator, 'a');
std.debug.print("{c}, {d}, {d}\n", .{char, keycode});
}
const isPangram: bool = seenCount == 26;
if (isPangram) {
std.debug.print("This is a pangram", .{});
} else {
std.debug.print("This is not a pangram", .{});
}
}
fn getKeycode(allocator: Allocator, char: u8) ![]u8 {
return std.fmt.allocPrint(allocator, "{d}", .{char});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment