If I understand you correctly, you're saying that while the program runs you are not seeing the result of individual putchar(c);
calls as they execute. Rather, you're seeing the output lumped together. You state you see it all only "at the end", but I suspect you actually see it all with each line at the time the carriage return is pressed.
Normal standard output to a terminal buffers up the characters to be written. That is, when you output something, that output doesn't get delivered to the system for actual output until some point that the buffer is flushed. In this situation, a carriage return (end of line) will flush the buffer; attempting to read input from the same channel will flush the buffer, and closing the channel (exiting the program) will flush the buffer. The purpose of this is to improve performance, since printing just a single character is very slow, while printing an entire buffer is nearly the same speed (performed once, rather than once per character).
If you want to manually flush the standard output buffer, you could include fflush(stdout);
after your putchar call.
Alternatively, you could disable buffering completely via setvbuf(stdout, NULL, _IONBF, 0);
Edit: As @JonatanGoebel points out, you also have a buffering situation on the getchar();
call and the input channel. You can't just fflush that channel, but you can disable buffering on it. If it remains buffered, the input will not come to your program until a carriage return is in it (and at that point, each successive getchar()
will return the next character in the buffer until you exhaust it and the call then must wait for the next buffer to fill).