M
Marcelo De Brito
Hi!
I have been rereading K&R classical C book and rewriting my older
codes to solve its exercises.
On the exercise 1.16 is asked to print the return value of 'getchar() !
= EOF' on the standard output. I modified that problem a little bit
not to only write that value just once, but each time a character is
entered in.
The final code is this one (it works flawlessly):
#include<stdio.h>
int main()
{
int c;
printf("\nType anything and, then, press 'ENTER'.\n\n");
while( (c = (getchar() != EOF)) )
printf("The value of '(getchar() != EOF)' is %d\n", c);
printf("The value of '(getchar() != EOF)' is %d\n", c); /*
Printing zero (CTRL+D) */
return 0;
}
My question is: What is the stop condition on the
loop "while( (c = (getchar() != EOF)) )" ?
It is interesting how C accepts some unusual expressions.
Any further explanation is welcomed!
Many thanks in advance!
Marcelo!
I have been rereading K&R classical C book and rewriting my older
codes to solve its exercises.
On the exercise 1.16 is asked to print the return value of 'getchar() !
= EOF' on the standard output. I modified that problem a little bit
not to only write that value just once, but each time a character is
entered in.
The final code is this one (it works flawlessly):
#include<stdio.h>
int main()
{
int c;
printf("\nType anything and, then, press 'ENTER'.\n\n");
while( (c = (getchar() != EOF)) )
printf("The value of '(getchar() != EOF)' is %d\n", c);
printf("The value of '(getchar() != EOF)' is %d\n", c); /*
Printing zero (CTRL+D) */
return 0;
}
My question is: What is the stop condition on the
loop "while( (c = (getchar() != EOF)) )" ?
It is interesting how C accepts some unusual expressions.
Any further explanation is welcomed!
Many thanks in advance!
Marcelo!