I understand how this program shows how getchar is using buffer to copy and paste more than one character
#include <stdio.h>
main()
{
int c;
c=getchar();
putchar(c);
c=getchar();
putchar(c);
}
but how does this code below
#include <stdio.h>
main()
{
int c;
c=getchar();
while (c!= EOF) // how does this program copy 12 and output 12. is a
{ buffer being used? How so?
putchar(c);
c=getchar();
}
}
show a buffer being used... i dont get it and i dont see how its able to print 12 when i input 12. im new to C
getchar
reads character by character from the standard input stream(stdin
). The thing is, the terminal doesn't flush the typed data into thestdin
until you press Enter. When you press it, characters are sent to thestdin
withgetchar
reading each character andputchar
outputting each one of them untilEOF
.No.... But sort-of.