It:
char ch;
incorrectly, EOF does not fit into char . The return type getchar() int , so this code should be:
int ch;
Also, as indicated, your logic is reversed. The while ch loop is not EOF , so you can just put it in a while :
while((ch = getchar()) != EOF)
source share