0

I tried getting user input with std.io.getStdIn().reader().readUntilDelimiter(buffer, '\n') but it results in a build error that doesn't provide much help:

Build Summary: 2/5 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install Test transitive failure
   └─ zig build-exe Test Debug native 1 errors
error: the following build command failed with exit code 1

I simplified the code to the bare minimum but it still presents the same bug:

const std = @import("std");

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

    const buffer: [1024]u8 = undefined;

    _ = try stdin.readUntilDelimiter(buffer, '\n');
}

Doing anything else without the readUntilDelimiter works fine, it's just the input function that freaks out.

Since the error message provided no help, I tried uninstalling and reinstalling Zig, but that didn't help either. Any help would be greatly appreciated.

Edit: It turns out the build fails just by calling std.io.getStdIn().reader(); without anything else.

1
  • 1
    zig version ? With 0.13.0, I get the same error message as @sigod Commented Jul 1, 2024 at 9:37

1 Answer 1

0

I get this error message:

src\main.zig:8:38: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
    _ = try stdin.readUntilDelimiter(buffer, '\n');
                                     ^~~~~~
  1. You need to use &buffer instead of buffer. The readUntilDelimiter takes a slice. The & operator coerces an array into a slice.
  2. And declare buffer as var instead of const.
Sign up to request clarification or add additional context in comments.

2 Comments

Hi, thanks for your answer. I think that would've been the solution if my computer wasn't weird. My build fails even just by calling std.io.getStdIn().reader(); without anything else, so I think the error has to do with the reader itself.
Zig is probably complaining about an unused local constant. You need to figure out why you're not seeing error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.