SlideShare a Scribd company logo
File in C ProgrammingFile in C Programming
File in C Programming
Contents
 Data Files
 File Types
 File opening and closing
 Data File Type Specifications
 Data File Creating
 Data File Processing
Data File
 A data file is a computer file which stores data for use by a
computer application or system.
 It generally does not refer to files that contain instructions or
code to be executed (typically called program files), or to files
which define the operation or structure of an application or
system (which include configuration files, directory files, etc.);
 but to files that specifically contain information used as input,
and/or written as output by some other software program.
Types of Data Files
Data Files of two Kinds
 Stream-oriented Data File or Standard Data File
 System-oriented Data File or Low-level Data File
Stream-oriented Data Files
Text File
Unformated Data File
Data Files Processing
Data Files Opening
FILE *ptvar; To create buffer area for file Handling
ptvar = fopen(filename, filetype);
To open a file and return a pointer that is assigned to ptvar.
Data Files Closing
fclose(ptvar); To close the file using the pointer ptvar.
Data File type
Specifications
“r” To open the file as read mode.
“w” To open the file as write mode.
“a” To open the file as append mode.
“r+” To open the file as read + write mode.
“w+” To open the file as write + read mode.
“a+” To open the file as append + read mode.
Data File Processing Functions
fopen() To open a file and return a pointer.
fclose() To close a file with the given pointer.
getchar() To take input from the standard input device.
putchar() To give output to the standard output device.
getc() To take input from the file.
putc() To give output to the file.
fprintf() To send output a data item to the file.
fscanf() To take input a data item from the file.
Data File Creating Program 1//program for creating a file test01.dat
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main()
{
FILE *fpt;
char c;
fpt=fopen("c:test01.dat","w");
clrscr();
printf("ntEnter text: ");
do
putc(toupper(c=getchar()),fpt);
while(c!='n');
fclose(fpt);
getch();
}
To create a buffer
area
To open a file and
return a pointer
To write a character
to the file
To close the file
Data File Reading Program
2
//program for reading and displaying from a file test01.dat
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main()
{
FILE *fpt;
char c;
clrscr();
if((fpt=fopen("test01.dat","r"))==NULL)
printf("nnError");
else
{
printf("ntText from the filen: ");
do
putchar(c=getc(fpt));
while(c!='n');
}
fclose(fpt);
getch();
}
To create a buffer
area
To open a file
To read a character
from a file and display
To close a file
File in C Programming

More Related Content

PPT
File in c
PPTX
File handling in c
PPSX
Files in c++
PPTX
Introduction to Selection control structures in C++
PPT
Input and output in C++
PPTX
Type casting in java
PPT
File in c
File handling in c
Files in c++
Introduction to Selection control structures in C++
Input and output in C++
Type casting in java

What's hot (20)

PPTX
Handling of character strings C programming
PDF
Friend function in c++
PDF
Python file handling
PPT
File handling in c
PPTX
C++ string
PPTX
Static Data Members and Member Functions
PPTX
07. Virtual Functions
PPTX
Type casting in c programming
PPTX
Operator overloading and type conversion in cpp
PDF
PPTX
Type casting
PPTX
Operator overloading
PDF
Python programming : Files
PPTX
Java input
DOC
Arrays and Strings
PPT
Class and object in C++
PPTX
C Programming Unit-5
PPTX
File in C language
Handling of character strings C programming
Friend function in c++
Python file handling
File handling in c
C++ string
Static Data Members and Member Functions
07. Virtual Functions
Type casting in c programming
Operator overloading and type conversion in cpp
Type casting
Operator overloading
Python programming : Files
Java input
Arrays and Strings
Class and object in C++
C Programming Unit-5
File in C language
Ad

Similar to File in C Programming (20)

DOCX
PPT
Lecture 20 - File Handling
PPTX
C-FILE MANAGEMENT.pptx
PPT
File_Handling in C.ppt
PPT
File_Handling in C.ppt
PPTX
File management
PPTX
File handling With Solve Programs
PDF
Module 03 File Handling in C
PDF
Files in c
PPTX
File handling in C
PPTX
file handling in c programming with file functions
PPTX
File management
PPTX
Data Structure Using C - FILES
PPT
Unit5
PDF
Files in C++.pdf is the notes of cpp for reference
PDF
file_c.pdf
PPT
file_handling_in_c.ppt
PPTX
PPS PPT 2.pptx
PDF
File Handling in C Programming
PDF
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
Lecture 20 - File Handling
C-FILE MANAGEMENT.pptx
File_Handling in C.ppt
File_Handling in C.ppt
File management
File handling With Solve Programs
Module 03 File Handling in C
Files in c
File handling in C
file handling in c programming with file functions
File management
Data Structure Using C - FILES
Unit5
Files in C++.pdf is the notes of cpp for reference
file_c.pdf
file_handling_in_c.ppt
PPS PPT 2.pptx
File Handling in C Programming
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
Ad

More from Sonya Akter Rupa (9)

PPTX
Synchronous Counter in Digital Logic Device
PPTX
Method Overloading in Java
PPTX
Enviremental Pollution
PPTX
Switch Case in C Programming
PPT
Pointer in C
PPTX
One Dimentional Array
PPTX
Two Dimentional Array
PPTX
The population is resource or burden for Bangladesh
PPT
Spherical Polar Coordinate System- physics II
Synchronous Counter in Digital Logic Device
Method Overloading in Java
Enviremental Pollution
Switch Case in C Programming
Pointer in C
One Dimentional Array
Two Dimentional Array
The population is resource or burden for Bangladesh
Spherical Polar Coordinate System- physics II

Recently uploaded (20)

PPT
Drone Technology Electronics components_1
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Ship’s Structural Components.pptx 7.7 Mb
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PDF
Top 10 read articles In Managing Information Technology.pdf
PDF
Queuing formulas to evaluate throughputs and servers
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPTX
metal cuttingmechancial metalcutting.pptx
PPT
SCOPE_~1- technology of green house and poyhouse
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
Glazing at Facade, functions, types of glazing
PDF
International Journal of Information Technology Convergence and Services (IJI...
PPTX
Simulation of electric circuit laws using tinkercad.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Practice Questions on recent development part 1.pptx
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
Drone Technology Electronics components_1
AgentX UiPath Community Webinar series - Delhi
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Ship’s Structural Components.pptx 7.7 Mb
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Top 10 read articles In Managing Information Technology.pdf
Queuing formulas to evaluate throughputs and servers
July 2025: Top 10 Read Articles Advanced Information Technology
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
metal cuttingmechancial metalcutting.pptx
SCOPE_~1- technology of green house and poyhouse
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Lesson 3_Tessellation.pptx finite Mathematics
Chapter 6 Design in software Engineeing.ppt
Glazing at Facade, functions, types of glazing
International Journal of Information Technology Convergence and Services (IJI...
Simulation of electric circuit laws using tinkercad.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Practice Questions on recent development part 1.pptx
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx

File in C Programming

  • 1. File in C ProgrammingFile in C Programming
  • 3. Contents  Data Files  File Types  File opening and closing  Data File Type Specifications  Data File Creating  Data File Processing
  • 4. Data File  A data file is a computer file which stores data for use by a computer application or system.  It generally does not refer to files that contain instructions or code to be executed (typically called program files), or to files which define the operation or structure of an application or system (which include configuration files, directory files, etc.);  but to files that specifically contain information used as input, and/or written as output by some other software program.
  • 5. Types of Data Files Data Files of two Kinds  Stream-oriented Data File or Standard Data File  System-oriented Data File or Low-level Data File Stream-oriented Data Files Text File Unformated Data File
  • 6. Data Files Processing Data Files Opening FILE *ptvar; To create buffer area for file Handling ptvar = fopen(filename, filetype); To open a file and return a pointer that is assigned to ptvar. Data Files Closing fclose(ptvar); To close the file using the pointer ptvar.
  • 7. Data File type Specifications “r” To open the file as read mode. “w” To open the file as write mode. “a” To open the file as append mode. “r+” To open the file as read + write mode. “w+” To open the file as write + read mode. “a+” To open the file as append + read mode.
  • 8. Data File Processing Functions fopen() To open a file and return a pointer. fclose() To close a file with the given pointer. getchar() To take input from the standard input device. putchar() To give output to the standard output device. getc() To take input from the file. putc() To give output to the file. fprintf() To send output a data item to the file. fscanf() To take input a data item from the file.
  • 9. Data File Creating Program 1//program for creating a file test01.dat #include <stdio.h> #include <conio.h> #include <ctype.h> void main() { FILE *fpt; char c; fpt=fopen("c:test01.dat","w"); clrscr(); printf("ntEnter text: "); do putc(toupper(c=getchar()),fpt); while(c!='n'); fclose(fpt); getch(); } To create a buffer area To open a file and return a pointer To write a character to the file To close the file
  • 10. Data File Reading Program 2 //program for reading and displaying from a file test01.dat #include <stdio.h> #include <conio.h> #include <ctype.h> void main() { FILE *fpt; char c; clrscr(); if((fpt=fopen("test01.dat","r"))==NULL) printf("nnError"); else { printf("ntText from the filen: "); do putchar(c=getc(fpt)); while(c!='n'); } fclose(fpt); getch(); } To create a buffer area To open a file To read a character from a file and display To close a file