Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Handling file in c programming, Study notes of C programming

file handling notes of c programming

Typology: Study notes

2018/2019

Uploaded on 10/04/2019

nikhil-pandey-1
nikhil-pandey-1 🇮🇳

2 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
File Handling
In programming it is not enough to just display the data on the screen. Because if data is large then it will
first take memory for store data then after it can be display on screen.
For storing the data in memory today we learn file handling.
In c programming two types of file on which we perform operation.
1. Text file
2. Binary file
Text File
This type of file are created using simple editor with (.txt ) extension and contain simple text.
Example - Notepad or other editor.
Binary File
This file contain the information in the binary code like - (1 or 0) and it is only read my machine.
It is represent by ( .bin ) extension.
Operation on file
1. Opening of file
2. Closing of file
3. Reading from file
4. Writing into file
5. Appending data into file
Mode of operation on file
File Mode Description
r
It opens an file for reading purpose.
If file does not exist , fopen() return Null
r+
It opens an file read and write purpose.
If file does not exist , fopen() return Null
w
it opens a text file for writing purpose . if file does not exist , then a new file is
created . if file exists it content are overwritten.
W+
it opens a text file for writing and reading purpose . if file does not exist , then a new
file is created . if file exists it content are overwritten
pf3
pf4

Partial preview of the text

Download Handling file in c programming and more Study notes C programming in PDF only on Docsity!

File Handling

In programming it is not enough to just display the data on the screen. Because if data is large then it will first take memory for store data then after it can be display on screen. For storing the data in memory today we learn file handling. In c programming two types of file on which we perform operation.

  1. Text file
  2. Binary file Text File This type of file are created using simple editor with (.txt ) extension and contain simple text. Example - Notepad or other editor.

Binary File This file contain the information in the binary code like - (1 or 0) and it is only read my machine. It is represent by ( .bin ) extension.

Operation on file

  1. Opening of file
  2. Closing of file
  3. Reading from file
  4. Writing into file
  5. Appending data into file Mode of operation on file

File Mode Description

r

It opens an file for reading purpose. If file does not exist , fopen() return Null

r+

It opens an file read and write purpose. If file does not exist , fopen() return Null

w

it opens a text file for writing purpose. if file does not exist , then a new file is created. if file exists it content are overwritten.

W+

it opens a text file for writing and reading purpose. if file does not exist , then a new file is created. if file exists it content are overwritten

a

It used to open a text file in writing append mode. If the file does not exist , then a new file is created

a+

It used to open a text file in reading and writing append mode. If the file does not exist , then a new file is created

Function in File handling

Function Name Description

fopen

Declaration: FILE *fopen (const char *filename, const char *mode) It is used to open a text file on given path It have two parameter where path (where file is created) and mode of operation FILE *fp; fp=fopen (“filename”, ”‘mode”);

fscanf

It is used to scan the file. It read a set of data from file.

fprintf

printf is used to print the information or data on output screen. fprintf is used to print information or data into the file. It has also two parameter file and message which is to be printed.

fclose

Declaration: int fclose(FILE *fp); It is used to close the file fclose (fp);

getc

Declaration: char *gets (char *string) It is used to get a character from file. gets (string);

putc

Declaration: int fputs (const char *string, FILE *fp) It is used to write a character to a file. fputs (fp, “some data”);

Program Example #include<stdio.h>