First of all, why are there no curly brackets after the if and while statements? And this program is supposed to be counting input lines but no matter what i input, it does not seem to be doing anything.

Also, how do I know I have reached EOF? There was an exercise to make a program that would print the value of EOF and I had no idea how to do this.

I' d appreciate anyone who could clear this up for me a bit.

Thanks : )

Post a Reply

Replies

statements don't require curly brackets unless you want to process more than one expression. EOF is end of file and it is represented as an int of -1 which will be returned into the c variable. whenever a newline character is returned into c, it will increment the nl variable.

getchar reads the characters parsed into stdin. by using file redirection, it is unnecessary to open the file in the program. this program isnt limited to file processing, you can run your program normally and type in whatever sequence of characters then pressing either Ctrl+D for *nix or Ctrl+Z for windows to send an EOF to end the while loop.