Guest User

Untitled

a guest
Dec 21st, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. const std = @import("std");
  2. const BYTES: []u8 = undefined;
  3.  
  4. pub fn main() !void {
  5.   const stdout = &(try std.io.getStdOut()).outStream().stream;
  6.   const allocator = &std.heap.FixedBufferAllocator.init(BYTES).allocator;
  7.  
  8.   var result: i32 = 0;
  9.  
  10.   while(true) {
  11.     var line_buf: [20]u8 = undefined;
  12.  
  13.     const line = std.io.readLineSlice(line_buf[0..]) catch |err| switch (err) {
  14.       error.OutOfMemory => {
  15.         try stdout.print("Input too long.\n");
  16.         continue;
  17.       },
  18.       error.EndOfStream => {break;},
  19.       else => return err,
  20.     };
  21.  
  22.     result += std.fmt.parseInt(i32, line, 10) catch {
  23.       try stdout.print("Invalid number.\n");
  24.       continue;
  25.     };
  26.   }
  27.  
  28.   try stdout.print("{}\n", result);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment