ProgrammingModerateProduct company OA

A file report.txt already exists and holds data. What does fopen("report.txt", "w") do?

  1. A. Opens it and positions writes after the existing data
  2. B. Opens it for reading only
  3. C. Opens it and truncates it to length zero, discarding the old contents
  4. D. Fails and returns NULL because the file already exists

Correct answer: C. Opens it and truncates it to length zero, discarding the old contents

Mode "w" creates the file or truncates an existing one. To keep the contents and add to the end, use "a"; to fail if the file exists, C11 offers "wx".

More C Programming questions

Exams that ask this topic