When should I use perror(“…”) and fprintf(stderr, “…”)?

前端 未结 5 1897
太阳男子
太阳男子 2020-12-07 07:53

Reading the man pages and some code did not really help me in understanding the difference between - or better, when I should use - perror(\"...\") or fp

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 08:38

    perror(const char *s): prints the string you give it followed by a string that describes the current value of errno.

    stderr: it's an output stream used to pipe your own error messages to (defaults to the terminal).

    Relevant:

    char *strerror(int errnum): give it an error number, and it'll return the associated error string.

提交回复
热议问题