Skip to content

Code error in section 12.1.1, comptime_arg_runtime_error.zig #227

@suraj083

Description

@suraj083

In the file ZigExamples/comptime/comptime_arg_runtime_error.zig, there is an error in line 17. If we look at lines 15-20

var buffer: [5]u8 = .{ 0, 0, 0, 0, 0 };
_ = try stdout.write("Please write a 4-digit integer number\n");
_ = try stdin.takeDelimiterExclusive('\n');

try stdout.print("Input: {s}", .{buffer});
const n: u32 = try std.fmt.parseInt(u32, buffer[0 .. buffer.len - 1], 10);

Here, "buffer" is defined on line 15 and it's referenced again in lines 19 and 20 but it is never updated to store the user input.

So, as we can expect when I run the file with "zig run", I get the following error message:

comptime-function-args.zig:15:9: error: local variable is never mutated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions