Devil
04-01-2002, 08:02 PM
can someone please explane how this code works.?
#include <stdio.h>
/* copy input to output */
main()
{
int c;
c = getchar();
while(c != EOF)
{
putchar(c);
c = getchar();
}
return 0;
}
it seems to enter the while loop without me pressing return.
If so why dosen't it print anything when it goes through the loop.
I seem to be having big problems understanding this simple scrap of code. I just don't get it why it enters the loop but dosen't do everything until you hit return. I also don't get how it can continue from the getchar() function without me pressing return.?
explenation needed...
#include <stdio.h>
/* copy input to output */
main()
{
int c;
c = getchar();
while(c != EOF)
{
putchar(c);
c = getchar();
}
return 0;
}
it seems to enter the while loop without me pressing return.
If so why dosen't it print anything when it goes through the loop.
I seem to be having big problems understanding this simple scrap of code. I just don't get it why it enters the loop but dosen't do everything until you hit return. I also don't get how it can continue from the getchar() function without me pressing return.?
explenation needed...