Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const std = @import("std");
- const BYTES: []u8 = undefined;
- pub fn main() !void {
- const stdout = &(try std.io.getStdOut()).outStream().stream;
- const allocator = &std.heap.FixedBufferAllocator.init(BYTES).allocator;
- var result: i32 = 0;
- while(true) {
- var line_buf: [20]u8 = undefined;
- const line = std.io.readLineSlice(line_buf[0..]) catch |err| switch (err) {
- error.OutOfMemory => {
- try stdout.print("Input too long.\n");
- continue;
- },
- error.EndOfStream => {break;},
- else => return err,
- };
- result += std.fmt.parseInt(i32, line, 10) catch {
- try stdout.print("Invalid number.\n");
- continue;
- };
- }
- try stdout.print("{}\n", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment