Ask Question
16 October, 01:08

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

+5
Answers (1)
  1. 16 October, 01:47
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers