Well, my question is, why do we need ( ch != EOF) ?
Code:
while(( ch = getchar()) != '\n' ); //understand
//don't understand the need of having != EOF
while ((ch = getchar()) != '\n' && ch != EOF);
So far the only reason I can think of is if user accidently pressed 'Enter' when he's being prompted to enter 2 inputs.
!= EOF can prevent the flushing ends before the 2nd '\n'
But, are there anymore reasons to it?
*ps : I just read in another post saying that "To indicate a read error or end-of-file condition, getc and getchar return EOF"
so does that means , ch != EOF is just for checking whether ch read in values correctly and it's not what I think ? O_O