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?

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195

1 Answers1

11

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

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195