🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Files and Preprocessor: all 10 questions

Quiz: Files and Preprocessor · Question 8 of 10

Which function reads a whole line of text, including spaces, from a file?

Which function reads a whole line of text, including spaces, from a file?

  1. A.fscanf(fp, "%s", buf)
  2. B.fgets(buf, size, fp)
  3. C.fputc(c, fp)
  4. D.fprintf(fp, "%s", buf)
Answer & explanation

Correct answer: fgets(buf, size, fp)

fscanf with %s stops at a space; fgets reads up to the newline or size - 1 characters.

Can you get the rest right without peeking?

Take the timed Quiz: Files and Preprocessor quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →