0% found this document useful (0 votes)
2 views

file

The document provides an overview of file handling in programming, specifically focusing on opening files and the associated modes. It explains the necessity of establishing a buffer area for data transfer and describes the use of the fopen() function to open files with different modes such as reading, writing, and appending. Additionally, it introduces the FILE structure defined in STDIO.H(), which contains information about the file's size, current location, and modes.

Uploaded by

Zayed Oyshik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

file

The document provides an overview of file handling in programming, specifically focusing on opening files and the associated modes. It explains the necessity of establishing a buffer area for data transfer and describes the use of the fopen() function to open files with different modes such as reading, writing, and appending. Additionally, it introduces the FILE structure defined in STDIO.H(), which contains information about the file's size, current location, and modes.

Uploaded by

Zayed Oyshik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

File Basics

Nakib Hayat Chowdhury


Department of Computer Science and Engineering
Bangladesh Army University Of Science And Technology
File Example

Input from a file

Output to a file
Open a File
To work with stream oriented data file first we need to established
a buffer area.

Where information is temporarily stored while being transferred


between memory and the data file.Up
. H pe
O I r
It’s done by D
T writing- re cas
n S qu e l
e i ire ett
f i n d ers
D e
FILE *fp;
Open a File…
A data file must be opened before it can be created or processed.

fopen (file_name, mode);


If the open operation is successful, fopen() returns a valid file
pointer.

The buffer area hold this.


fp = fopen (file_name, mode);

FILE *fp;
fp = fopen (file_name, mode);
FILE *fp
The FILE is defined in STDIO.H()

It is a structure that holds various kinds of information about the


file.

its size

the current location of file

its associated modes


fp = fopen (file_name, mode);

FILE *fp;
fp = fopen (file_name, mode);
Mode and Meaning
If a file with the specified file-name
currently exists, it will be destroyed and
a new file created in its place

A new file will be created if the file


Mode Meaning
with the specific file-name does not
exist. “r” Open an existing file for reading only
“w” Open a new file for writing only.
“a” Open an existing file for appending (for adding new
information at the end)
“r+” Open a text file for both reading and writing
“w+” Create a text file for both reading and writing
“a+” Appending read/write
File Example

fprintf() and fscanf()

You might also like