(i) New Lines:-In text mode, a newline character is converted into the carriage return -linefeed combination before being written to the disk. Like wise, the carriage return-line feed combination on the disk is converted back in to a newline when the file is read by a c program. However if file is opened in binary mode, as opposed to text mode, these conversions will not take place.
(ii) End of File:-The difference is that in text mode when end-of-file is detected a special character whose asciI value is 26, is inserted after the last character in the file to mark the end of file. If this character is detected at any point in the file, the read function will return the EOF signal to the program.
As against this, there is no such special character present in the binary mode files to mark the end of file. The binary mode file keeps track of the end of file from the number of characters present in directory entry of the file.
Text Mode:-
The only function available for storing in a disk file is the fprintf( ) in text mode. Here numbers are stored as string of characters when written to the disk. These 1234, even though it occu- pies two bytes in memory, when transferred to the disk using fprintf( ), it would occupy four bytes, one byte per character. Similarly the floating point number 1234.56 would occupy 7 bytes on disk. These, numbers with more digits would require more disk space.
In binary by using the functions (fread( ) and fwrite( )) numbers are stored in binary format. It means each number would occupy the same number of bytes on disk as it occupies in memory.
Binary Mode:-
A file can be opened in binary mode as follows:
fp = fopen(“Poem. txt”, “rb”)
Here fp is file pointer
Poem. txt is file name
rb denotes that file is opened in binary mode for read operation.
(ii) End of File:-The difference is that in text mode when end-of-file is detected a special character whose asciI value is 26, is inserted after the last character in the file to mark the end of file. If this character is detected at any point in the file, the read function will return the EOF signal to the program.
As against this, there is no such special character present in the binary mode files to mark the end of file. The binary mode file keeps track of the end of file from the number of characters present in directory entry of the file.
Text Mode:-
The only function available for storing in a disk file is the fprintf( ) in text mode. Here numbers are stored as string of characters when written to the disk. These 1234, even though it occu- pies two bytes in memory, when transferred to the disk using fprintf( ), it would occupy four bytes, one byte per character. Similarly the floating point number 1234.56 would occupy 7 bytes on disk. These, numbers with more digits would require more disk space.
In binary by using the functions (fread( ) and fwrite( )) numbers are stored in binary format. It means each number would occupy the same number of bytes on disk as it occupies in memory.
Binary Mode:-
A file can be opened in binary mode as follows:
fp = fopen(“Poem. txt”, “rb”)
Here fp is file pointer
Poem. txt is file name
rb denotes that file is opened in binary mode for read operation.