G
Gladiator
When I am trying to execute a program from "The C Programming Language"
by Dennis Ritchie, I tried to run the following program.I am using
Dev++ as a compiler software. The
Program is presented below.
#include <stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%1d\n",nc);
}
Whatever I am typing, It is displayed in the black window. I am not
able to reach the EOF as specified in the While statement even after
giving a considerable inputs. I have 2 questions.
1st is I simply cannot understand the logic of the program
even after going through it.
Whatever the input we are typing in is appearing in the window. Is
there any where the data is being stored. I would be thankful if
someone could explain the use of the program in layman's language.
2nd question is, we are using the EOF to compare it with a
value. Is it necessary to specify the EOF value before we use it in a
comparison?. One way what i could think is the EOF value may be the
maximum value that the variable can hold ( In this "Long"). But I am
not sure about it.
Please help me to understand it.
by Dennis Ritchie, I tried to run the following program.I am using
Dev++ as a compiler software. The
Program is presented below.
#include <stdio.h>
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%1d\n",nc);
}
Whatever I am typing, It is displayed in the black window. I am not
able to reach the EOF as specified in the While statement even after
giving a considerable inputs. I have 2 questions.
1st is I simply cannot understand the logic of the program
even after going through it.
Whatever the input we are typing in is appearing in the window. Is
there any where the data is being stored. I would be thankful if
someone could explain the use of the program in layman's language.
2nd question is, we are using the EOF to compare it with a
value. Is it necessary to specify the EOF value before we use it in a
comparison?. One way what i could think is the EOF value may be the
maximum value that the variable can hold ( In this "Long"). But I am
not sure about it.
Please help me to understand it.