Ticker

6/recent/ticker-posts

File handling in C Programming Language

File handling

File: the file is a permanent storage medium in which we can store the data permanently. 

Types of file can be handled 

we can handle three type of file as 

(1) sequential file 

(2) random access file 

(3) binary file 

File Operation 

opening a file: 

 Before performing any type of operation, a file must be opened and for this fopen() function is used. 

syntax: 

file-pointer=fopen(“FILE NAME ”,”Mode of open”); 

example: 

FILE *fp=fopen(“ar.c”,”r”); 

If fopen() unable to open a file than it will return NULL to the file pointer. 

File-pointer: The file pointer is a pointer variable which can be store the address of a special file that means it is based upon the file pointer a file gets opened. 

Declaration of a file pointer:- 

FILE* var; 

Modes of open 

The file can be open in three different ways as 

        Read mode ’ r’/rt 

        Write mode ’w’/wt 

        Appened Mode ’a’/at

Reading a character from a file 

getc() is used to read a character into a file 

Syntax: 

        character_variable=getc(file_ptr); 

ALSO SEARCH:

"file handling in c"

"file handling functions in c with syntax"

"types of file handling in c"

"file handling in c"

"files in c programming"

"c program to read and write to a file"