So here is short/simple program that just takes your keyboard input, and outputs it when you press enter:
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int c = getchar();
while(c != EOF)
{
putchar(c);
c = getchar();
}
}
In "The C Programming Language" book, the author says doing this is more terse equivalent:
Code:
int main()
{
int c = getchar();
while((c = getchar()) != EOF)
{
putchar(c);
}
}
However, the behavior is slightly different, on the first input, it removes a character. I can't figure out why: