The following is a program to count the number of characters:
#include<stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%ld\n", nc);
}
As we have seen here- Why does getchar() recognize EOF only in the beginning of a line? that ctrl+z is not considered as EOF when written within a line of characters and is considered as EOF only when written at the beginning of line.
So these are some of the following outputs of the program:
123
abs
^Z
8
Here the program returns 8 so it means it is counting the '\n' as well.
123^Z
abs^Z
^Z
8
It again returns 8 so what is the program doing here? Either it is ignoring ^Z as a character or it is not counting the '\n' after the ^Z.
abc^Zaa
^Z
4
Here the program is returning 4 so it means that it is not counting aa after ctrl+Z. So I want to know whether it is not counting any characters after ^Z or it is also not counting ^Z but is counting the newline character at the end of each line. So can it be said that ^Z here is also acting as sort of end of line?