in your program, you read the character from the input std as c = getchar ();
this way you can get the ascii value of the pressed key, which will never be equal to EOF.
since EOF is the end of the file.
itβs best to try to open any existing file and read from the file, so when it reaches End of File (EOF) it will end the while loop.
Good answer in the book:
int main() { printf("Press a key\n\n"); printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF); }
try to understand the program, it will get a key that will not be equal to EOF, so it should always print "Expression getchar ()! = EOF evaluates to 0".
hope this helps .......
Kinjal patel
source share