Ask Question

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

+2
Answers (1)
  1. 22 May, 01:27
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers