Flat 20% & up to 50% off + Free additional Courses. Hurry up!

File Handling in C


File handling is used to store the data permanently in files. It is used to open, store, read, search or close files.

Functions Use
fopen() opens new or existing file
fprintf() write data into file
fscanf() reads data from file
fputc() writes a character into file
fgetc() reads a character from file
fclose() closes the file
fseek() sets the file pointer to given position
fputw() writes an integer to file
fgetw() reads an integer from file
ftell() returns current position
rewind() sets the file pointer to the beginning of the file


There are different modes available for opening a file:

Mode Use
r opens a text file in read mode
w opens a text file in write mode
a opens a text file in append mode



#include <stdio.h>

#include <conio.h>

void main()


FILE *fptr;

int rollno;

char name[50];

fptr = fopen("student.txt", "w+");/*  open for writing */

//student .txt is a file in which we store the data

if (fptr == NULL)


printf("File does not exists \n");



printf("Enter the Rollno\n");

scanf("%d", &rollno);

fprintf(fptr, "Rollno= %d\n", rollno);

printf("Enter the name \n");

scanf("%s", name);

fprintf(fptr, "Name= %s\n", name);




Enter Rollno 20 Enter the name rishi

Then if we open the student.txt file then it contains-

Rollno = 20

Name = rishi

"0 Responses on File Handling in C"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.


Sales Offer

  • To avail this offer, enroll before 27th October 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
DW offer

Sign Up or Login to view the Free File Handling in C.