input - How do I read until the end of file? -
in c, can read input , stop program when reaches end of file (eof
). so.
#include <stdio.h> int main(void) { int a; while (scanf("%d", &a) != eof) printf("%d\n", a); return 0; }
how can in lua?
the lua documentation features ton of details on file-reading , other io. reading entire file:
t = io.read("*all")
apparently reads entire file. documentation has examples on reading line-by-line etc. hope helps.
example on reading lines of file , numbering each of them (line-by-line):
local count = 1 while true local line = io.read() if line == nil break end io.write(string.format("%6d ", count), line, "\n") count = count + 1 end
Comments
Post a Comment