LearnFrenzy
Sign in Take a free test

C Input / Output · Find the Error · Question 5

Error: fprintf called like printf Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program below has a bug. Which statement correctly describes it?

main.c
#include <stdio.h>

int main(void) {
    int code = 404;
    fprintf("error %d\n", code);
    return 0;
}
  • A %d must be %i
  • B fprintf's first argument must be a FILE * stream, e.g. fprintf(stderr, "error %d\n", code) Correct
  • C code must be a string
  • D There is no bug
Correct Answer: Option B

Here the format string is passed as the stream and the int as the format, which the compiler rejects. Error messages usually go to stderr.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links