In addition to Jon Lin's answer about EOF, I am not sure the code you wrote is what you intended. If you want to see the value returned from getchar
in the variable d
, you need to change your while
statement to:
while((d=getchar())!=EOF) {
This is because the inequality operator has higher precedence than assignment. So, in your code, d
would always be either 0
or 1
.