Ask Question
22 September, 22:19

When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string?

+4
Answers (1)
  1. 22 September, 23:00
    0
    Assuming we're talking C here:

    I would opt for fread () with the following notes:

    - there are no guarantees that the whole file counts as one string.

    - you need to know the length of the file to allocate enough memory.

    - you need to append a trailing 0 in memory to terminate the string.

    fgets () does return a 0-terminated string but is not exactly what is asked since it only reads until the next newline character which may be in the middle of the file.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string? ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers