I am in the process of learning C programming and K & R is the book of choice. While going through book examples on getchar & putchar; I decided to tweak the example a bit (just to have a better understanding). Now I am confused.
Code:
#include <stdio.h>
main()
{
int c;
c = getchar();
while (c != EOF)
{
printf ("I knew youd type: ");
putchar (c);
c=getchar();
}
}
Output:
Code:
4
Somehow I know youd type:4Somehow I know youd type:
My expected/desired output should have been:
Code:
4
Somehow I know youd type: 4
The question is why the comments within printf is getting printed again. The program should have stopped at getchar() which was within the while statement block? Why isn't that happening? Can anyone please help me in clearing my logic here?