Name: Edward 2006-07-30 19:04
The following segment of code is supposed to get characters and repeat them back at me until EOF is entered, variable c has been declared as int.
However the debug output shows that getchar() is acting weird:
1
Debug:: c = 49
Debug:: c = 10
2
Debug:: c = 50
Debug:: c = 10
It seems like the loop is running once more everytime I hit enter. Is this a problem with:
a) This use of getchar in a while() condition (K&R says this is okay)?
b) A problem with gcc? (running on OS X)
c) Something else?
Please help...
while((c = getchar()) != EOF)
{
printf("Debug:: c = %d\n", c);
}However the debug output shows that getchar() is acting weird:
1
Debug:: c = 49
Debug:: c = 10
2
Debug:: c = 50
Debug:: c = 10
It seems like the loop is running once more everytime I hit enter. Is this a problem with:
a) This use of getchar in a while() condition (K&R says this is okay)?
b) A problem with gcc? (running on OS X)
c) Something else?
Please help...