In section 1.6 of ‘The C Programming Language’ (K&R) there is an example program and the authors state:
The output of this program ON ITSELF is
digits = 9 3 0 0 0 0 0 0 0 1, white space = 123, other = 345
Then there are many similar programs etc. including exercises. I understand everything about the logic of the code and can do the exercises, but how do I actually test my program on a file like the authors or many others on the web?
Edit: The question should be: How can I redirect the input of a file to the program?
The program in chapter 1.6 reads input from stdin. To make it read from a file, you can (on most operating systems) redirect stdin to be a file by running your program like this:
Or you can pipe the content of a file to it like so:
On windows, you’d use the
typeprogram instead ofcat,