I think the problem is because you're using EOF to check a character, try


while((ch=getchar())!='0')

instead of


while((ch=getchar())!=EOF)