[prev] 34 [next]

Using stderr for error Messages

  • fprintf allows you to specify stream to print to
  • For example:

    fprintf(stderr, "error: can not open %s\n", argv[1]);
    

  • printf actually just calls fprintf specifying stdout

    fprintf(stdout, ...);
    

  • Best if error messages written to stderr, so users sees them even if stdout is directed to a file.
  • Common for stderr to be redirected separately to a log file for system programs.