Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Code:
#include <stdio.h> int main() { long cn=1; char ch; while((ch=getchar())!=EOF) { printf("%ld\t%c\n",cn++,ch); } }
When I input word "secret" and hit enter it shows count up to 7 and not 6,why?
EOF
getchar
int
char
Because the "enter" character is read as well. This is in fact a "newline", ASCII code 10 (or hex 0A).
Add a comment
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
EOFmust differ from any character! Thusgetcharreturnsint, notchar. Enable compiler warnings and take them seriously!