I created a file like this
a v bb e
And I didn't press enter
after typing e
in the last line.
So there are four characters in the first line 'a',' ','v','\n'
.
There are three characters in the second line 'b','b','\n'
.
And there is one character in the last line 'e'
.
So there are totally 8 characters in this file. But when I count the characters using the following C program:
#include<stdio.h>
/* count characters in input; 1st version */
int main()
{
long nc;
nc = 0;
while (getchar() != EOF) {
++nc;
}
printf("%ld\n", nc);
return 0;
}
It gave me 9. Even when I use wc
command to count, it is still 9. Why?