Created
December 19, 2020 08:27
-
-
Save Heppokoyuki/049a7c4bd0a3f32b720671e01c3e32c2 to your computer and use it in GitHub Desktop.
nittc-procon advent calendar 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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