Skip to content

Instantly share code, notes, and snippets.

@Heppokoyuki
Created December 19, 2020 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Heppokoyuki/049a7c4bd0a3f32b720671e01c3e32c2 to your computer and use it in GitHub Desktop.
Save Heppokoyuki/049a7c4bd0a3f32b720671e01c3e32c2 to your computer and use it in GitHub Desktop.
nittc-procon advent calendar 2020
const std = @import("std");
fn read_num(comptime T: type, stdin: *const std.fs.File) T {
var buf: [64]u8 = undefined;
const len = stdin.read(&buf) catch |err| {
std.debug.warn("Error while reading number: {}\n", .{err});
std.os.exit(1);
};
if (len == buf.len) {
std.debug.warn("Input is too big!\n", .{});
std.os.exit(1);
}
const line = std.mem.trimRight(u8, buf[0..len], "\r\n");
const val = std.fmt.parseInt(T, line, 10) catch |err| {
std.debug.warn("Error while parsing number: {}\n", .{err});
std.os.exit(1);
};
return val;
}
pub fn main() anyerror!void {
const stdin = std.io.getStdIn();
var v: u16 = undefined;
const data: usize = 80;
std.debug.warn("please input number: ", .{});
v = read_num(u16, &stdin);
std.debug.warn("v: {}, data: {}\n", .{ v, data });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment