A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
Three streams are opened automatically when your program starts: stdin, stdout, stderr. stdout is for program output. stderr is for diagnostics, errors, and warnings. They are separate so that a user can redirect output to a file while still seeing error messages on the terminal. If you mix them, you break shell pipelines and make debugging harder for everyone downstream.
#include <stdio.h>int main(void) {fprintf(stdout, "Result: 42\n");fprintf(stderr, "Warning: input file was empty, using defaults\n");fprintf(stdout, "Result: 99\n");return 0;}
The warning appeared on the terminal even though stdout was redirected to a file. That is the point. The user sees the diagnostic immediately. The clean output goes to the file for further processing. If both had gone to stdout, the warning would be buried in output.txt and the user would never see it.
stdout is typically line-buffered when connected to a terminal and fully buffered when redirected to a file. stderr is unbuffered. Every fprintf(stderr, ...) call flushes immediately. This matters when your program crashes. Buffered stdout data might be lost because the buffer was never flushed. stderr data is already on the terminal. Your crash diagnostic survives.
#include <stdio.h>#include <stdlib.h>int main(void) {fprintf(stdout, "This might be lost if we crash before flush\n");fprintf(stderr, "This is already on the terminal\n");abort();return 0;}
The stdout line was in the buffer when abort killed the process. It never made it to the file. The stderr line was already written. In a crash investigation, that difference determines whether you see the diagnostic or stare at an empty log wondering what happened.
Use stderr for errors, warnings, progress indicators, and debug output. Use stdout for the actual data your program produces. This separation is a Unix convention that every shell script, pipeline, and log aggregator depends on. Break it and you make life harder for every user who pipes your output. Next module: system interaction, starting with command-line arguments.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.