Discussion: Hello, stdin
Execute the code to understand the output and gain insights into buffer management.
We'll cover the following...
Run the code
Now, it's time to execute the code and observe the output. After you press the "Run" button, press "Enter" to see the output.
#include <stdio.h> int main() { char buffer[BUFSIZ]; /* BUFSIZ is a constant defined in stdio.h */ setbuf(stdout, buffer); puts("Wait for it!"); puts("Wait for it!"); puts("Now!"); getchar(); puts("Whew!"); return(0); }
C code for the given puzzle
Understanding the output
No output is generated when the program starts. Press the "Enter" key, and the following text appears:
Wait for it!Wait for it!Now!Whew!
Code output
...