const std = @import("std");
pub fn main() !void {
var bytes: [3]u8 = .{ 0, 0, '4' };
bytes[1] = '4';
bytes[2] = '2';
const val = try std.fmt.parseInt(u8, &bytes, 10);
std.debug.print("Parsed bytes {s} as {d}\n", .{ bytes, val });
}
In this example, I am trying to construct a string of integer characters and then parse that string into a u8. However, this produces the following output:
$ zig build run
error: InvalidCharacter
/usr/lib64/zig/9999/lib/std/fmt.zig:1763:17: 0x1072362 in charToDigit (tmp_zig)
else => return error.InvalidCharacter,
^
<snip, message too long>
what's the correct way to build this string piece-by-piece and then later convert to an integer?