0

Is there a difference between the following two statements:

fprintf(stderr, "Hello this is something\n");
printf("Hello this is something\n");

If there is, what's the difference, and when would one be used over the other?

  • If it is an error message, it should properly be output on `stderr`, normal output should go to `stdout`. Also, if there are no conversion specifiers, there is no need for `(f)printf`, simply use `fputs`, e.g. `fputs ("error: Hello this is something -- failed\n", stderr);` – David C. Rankin Sep 24 '19 at 02:54

1 Answers1

1

For your specific 2 Ines of code, no they're not the same.

printf only writes to stdout (not stderr)

You would use fprintf when you want to write to a different stream then stdout.

CeePlusPlus
  • 640
  • 6
  • 22