I input a text file into my C program by using the <
I/O redirection in the terminal:
MyProgram.exe < "data.txt"
And then use getchar()
and scanf()
in my code to read from the redirected input. However, as this is a redirected file, I can't use a C file pointer to rewind the buffer.
(I want to count the number of lines in a file of an arbitrary size so I can initialize an array, then I want to re-read the file using getchar()
and/or scanf()
).
How do I achieve a rewind or flush when using redirected input?