Basic File Operations
Basic File Operations
D. YASHWINI NAIK
23B81A05NM
CSE-J
Importance of File Operations in
Data Handling - File operations are
crucial for managing data that needs to
Definition of File be saved and retrieved beyond the
program's runtime. They enable data
Operations: File operations persistence, data transfer, and data
are actions performed on manipulation.
Types of Files -1. Text Files:
files, such as creating, Files that contain human-readable
opening, reading, writing, characters. Examples include .txt files.
and closing files. These 2. Binary Files: Files containing
binary data, which is not human-
operations allow programs to readable. Examples include .bin files.
store data persistently.
Example:
Opening and closing Files: FILE *filePointer;
Opening Files with “fopen”: filePointer=fopen("example.txt", "r");
if (filePointer == NULL) {
The “fopen” function is used to open a file. It requires two // Handle error
arguments: *The name of the file to open. printf("File could not be opened.\n");}
The mode in which to open the file (e.g., "r" for reading,
"w" for writing, “a" for appending).