Below is my code to count number of characters.
#include<stdio.h>
int main()
{
int count=0; /*better to initialise a large number */
int c;
while(getchar() != EOF)
{
count++;
}
printf("\nNumber of character seen so far is %d\n",count);
return 0;
}
Input:
abcd^D
^D
Output seen:
Number of character seen so far is 5
Output expected:
Number of character seen so far is 4
after d I am entering ^D to send EOF signal. But it is not working there and when I enter new line and send ^D, EOF signal is read.
Am i missing something here? Why the signal is not going through in first case.