0

Why fprintf with stderr ??

Hi! I'm unable to understand why I will use: fprintf(stderr, "Error: %s", strerror(errno)); When I can use: printf("Error: %s", strerror(errno)); And perror("Error"); Can anyone explain? I don't think I have to use fprintf. And can I do something about user defined function that it's error can be printed by "perror()". I mean I want to make a custom error that can be used by strerror(errno) or perror()

16th Mar 2021, 8:23 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
4 Réponses
+ 2
you're not mandatory to output error message to stderr rather than stdout (default output for printf), but you are strongly advised to do so, to separate normal output from error output: this let user filter output of your program by stream ;)
16th Mar 2021, 8:32 PM
visph
visph - avatar
+ 1
no, because I'm not aware of how error handling is done in C... :(
17th Mar 2021, 8:24 PM
visph
visph - avatar
0
visph Can you help me with my second question
17th Mar 2021, 8:22 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
visph Ok Thanks 😊
17th Mar 2021, 8:24 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar