I have the following code which basically acts as a typewriter:

int main ()
{
	char c;
	puts ("Enter text:");
	do {
		c=getchar();
		putchar (c);
	} while (!feof(stdin));
	return 0;
}

However when I feed it a text file for input: $ ./typewriter < input.txt it always adds a ? at the end of the output. I'm not sure why this is happening, can anyone please point me to a reason why?

Thanks in advance!

Probably because that code prints the EOF character. Try this one. Variable C needs to be int, not char.

int c;
while( (c = getchar()) != EOF)
   putchar(c);

Probably because that code prints the EOF character. Try this one. Variable C needs to be int, not char.

int c;
while( (c = getchar()) != EOF)
   putchar(c);

Ah, perfect. Thank you!