
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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.
- Related Articles
- What are the different operations on files in C language?
- Difference between files written in binary and text mode in C++
- Why files are needed in C programming language?
- Endian order and binary files in C++
- Explain the Random accessing files in C language
- Explain the custom header files in C language
- Reading and Writing to text files in C#
- Explain putc() and getc() functions of files in C language
- Explain write mode operation of files in C language
- Explain read mode operation of files in C language
- Explain append mode operation of files in C language
- Reading and Writing to text files in Python
- How to print the content into the files using C language?
- What are .pyc files in Python?
- Recursive Search and Replace in Text Files in Linux
