What are the text files and binary files in C language?


Files is collection of records (or) it is a place on hard disk, where data is stored permanently.

Types of Files

There are two types of files in C language which are as follows −

  • Text file
  • Binary File

Text File

  • It contains alphabets and numbers which are easily understood by human beings.

  • An error in a text file can be eliminated when seen.

  • In text file, the text and characters will store one char per byte.

  • For example, the integer value 4567 will occupy 2 bytes in memory, but, it will occupy 5 bytes in text file.

  • The data format is usually line-oriented. Here, each line is a separate command.

Binary file

  • It contains 1’s and 0’s, which are easily understood by computers.

  • The error in a binary file corrupts the file and is not easy to detect.

  • In binary file, the integer value 1245 will occupy 2 bytes in memory and in file.

  • A binary file always needs a matching software to read or write it.

  • For example, an MP3 file can be produced by a sound recorder or audio editor, and it can be played in a music player.

  • MP3 file will not play in an image viewer or a database software.

Files are classified into following

  • Sequential files − Here, data is stored and retained in a sequential manner.
  • Random access Files − Here, data is stored and retrieved in a random way.

Updated on: 09-Mar-2021

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements