| ... | ... | @@ -9,8 +9,6 @@ pub fn main() !void { |
| 9 | 9 | var stdout_file_stream = io.FileOutStream.init(&stdout_file); |
| 10 | 10 | const stdout = &stdout_file_stream.stream; |
| 11 | 11 | |
| 12 | | var stdin_file = try io.getStdIn(); |
| 13 | | |
| 14 | 12 | try stdout.print("Welcome to the Guess Number Game in Zig.\n"); |
| 15 | 13 | |
| 16 | 14 | var seed_bytes: [@sizeOf(u64)]u8 = undefined; |
| ... | ... | @@ -27,12 +25,15 @@ pub fn main() !void { |
| 27 | 25 | try stdout.print("\nGuess a number between 1 and 100: "); |
| 28 | 26 | var line_buf : [20]u8 = undefined; |
| 29 | 27 | |
| 30 | | const line_len = stdin_file.read(line_buf[0..]) catch |err| { |
| 31 | | try stdout.print("Unable to read from stdin: {}\n", @errorName(err)); |
| 32 | | return err; |
| 28 | const line_len = io.readLine(line_buf[0..]) catch |err| switch (err) { |
| 29 | error.InputTooLong => { |
| 30 | try stdout.print("Input too long.\n"); |
| 31 | continue; |
| 32 | }, |
| 33 | error.EndOfFile, error.StdInUnavailable => return err, |
| 33 | 34 | }; |
| 34 | 35 | |
| 35 | | const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) catch { |
| 36 | const guess = fmt.parseUnsigned(u8, line_buf[0..line_len], 10) catch { |
| 36 | 37 | try stdout.print("Invalid number.\n"); |
| 37 | 38 | continue; |
| 38 | 39 | }; |