How I can print to stderr in C?

后端 未结 6 1379
既然无缘
既然无缘 2020-12-23 00:11

In C, Printing to stdout is easy, with printf from stdio.h.

However, how can print to stderr? We can use fprintf to achieve it

6条回答
  •  执念已碎
    2020-12-23 00:58

    Some examples of formatted output to stdout and stderr:

    printf("%s", "Hello world\n");              // "Hello world" on stdout (using printf)
    fprintf(stdout, "%s", "Hello world\n");     // "Hello world" on stdout (using fprintf)
    fprintf(stderr, "%s", "Stack overflow!\n"); // Error message on stderr (using fprintf)
    

提交回复
热议问题