Professional Documents
Culture Documents
8 File Handling in C PDF
8 File Handling in C PDF
File.
A file is used for permanent storage.
Opening a file.
FILE *fp;
fp is a file pointer variable which contains address of structure FILE
which is defined in stdio.h
fopen(file-name,opening mode);
file-name name of the file to open.
opening-mode mode in which is file is to be opened. This may be:
r reading mode.
w writing mode.
a appending mode.
e.g. fopen(abc.txt,r);
it will open file in reading mode. Means we can only read
its data.
fscanf
name
name
File
Writing to a file
fprintf is used to write the contents to the file.
Syntax:
fscanf(file-pointer,access-specifier,variables);
e.g. FILE *fp;
char name[10];
fp = fopen(abc.txt, w);
fprintf(fp,Your name : KKWP);
This will print Your name : KKWP
in the file name abc.txt.
Created By,
Mr.
Tushar B Kute,