0

Working my way through K&R and having a hard time understanding the behavior of getchar. Consider the following code

#include <stdio.h>

void main()
{
        int c;

        while (( c = getchar()) != EOF)
        {
                putchar(c);
        }
}

I would expect this program to output each character as I type it, but instead the loop only executes after a newline has been entered. Does getchar not return until a newline is entered?

Thank you in advance for any explanation

0 Answers0