C Programming - Input / Output - Discussion

2. 

A file written in text mode can be read back in binary mode.

[A]. Yes
[B]. No

Answer: Option B

Explanation:

The difference is that text files contain lines (or records) of text and each of these has an end-of-line marker automatically appended to the end of it whenever you indicate that you have reached the end of a line.

Binary files are not broken up into separate lines or records so the end-of line marker is not written when writing to a binary file.

So, we cannot read the correct the data in binary mode.


Mrmino said: (Jan 25, 2016)  
The file written as text can be read with fread (& some_char, sizeof (char), 1, input); in loop. It will spew out eols anyway. As long as text is encoded in ASCII.

Jim Dines said: (Sep 2, 2017)  
The answer to this question is yes. You can read the file back just fine. When you do it will have the appropriate CR/LF or LF at the end of each line that was written/appended when opened in text mode.

I also agree @Mrmino.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.