C Programming language

Way of storing data in File using C
Previous Home Next

There are two ways of storing data in files.

  1. Text Format: In text format data is stored as a line of character with each line terminated by a new line character ('\n'). Text files are in human readable form they can be created and read using any text editor.

  2. Binary Format: In binary format data is stored on the disk same way as it is represented in the computer memory . binary files are not in human readable form they can be created and read by a specific program written for them .The binary data stored in the file can-t be read by any editor.

    The input and output operation in binary files take less time as compared to that of the text files because in binary files no conversion have to take place .However the data written using binary format is not very portable since the size of data types and byte order may be different on different machine. In text format , these problem do not arise. so it is more portable.

Concept of Buffer in file Handling

Buffer is an area in memory where the data is temporarily stored before being written to the file .when we open a file , a buffer is automatically associated with its file pointer. whatever data be send to the file is not immediately written to the file .

First it send to the buffer and when the buffer is full then its contents are written to the file . When the file is closed all the contents of buffer are automatically written to the file even is buffer is not full .this is called flushing the buffer. we can also explicitly flush the buffer by a function fflush( ). The concept of buffer is used to increase the efficiency.

Previous Home Next