1

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?

2

1 Answer 1

11

Because the "enter" character is read as well. This is in fact a "newline", ASCII code 10 (or hex 0A).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you,I was making reading Ritchie C book and making a quiz for www.embeddedfunda.com

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.