There is an ungetc function that allows you to return a character to a stream. This is not a standard C function, but implemented on Unix-like systems and Visual Studio CRT:
while ((c = getchar()) != EOF) { ungetc(c, stdin); fgets(in, 1000, stdin); fputs(in, stdout); }
But, as other responders point out, a cleaner way to do this is to use fgets() directly:
while (fgets(in, sizeof(in), stdin) != NULL)
The third option is to save the first character directly in the line:
while ((c = getchar()) != EOF) { in[0] = c; fgets(in + 1, 999, stdin); fputs(in, stdout); }
myaut source share