SlideShare uma empresa Scribd logo
1 de 11
File in C ProgrammingFile 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

Mais conteúdo relacionado

Mais procurados

Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++Jaspal Singh
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams Ahmed Farag
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++Ashok Raj
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
File Management in C
File Management in CFile Management in C
File Management in CPaurav Shah
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CAshim Lamichhane
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++ Hridoy Bepari
 

Mais procurados (20)

Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Storage classes in c++
Storage classes in c++Storage classes in c++
Storage classes in c++
 
Files in c++
Files in c++Files in c++
Files in c++
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
File in C language
File in C languageFile in C language
File in C language
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Structures
StructuresStructures
Structures
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
File Management in C
File Management in CFile Management in C
File Management in C
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
The process states
The process statesThe process states
The process states
 

Semelhante a File in C Programming

Semelhante a File in C Programming (20)

Unit 8
Unit 8Unit 8
Unit 8
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptx
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
 
File_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
 
File management
File managementFile management
File management
 
File handling With Solve Programs
File handling With Solve ProgramsFile handling With Solve Programs
File handling With Solve Programs
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
Files in c
Files in cFiles in c
Files in c
 
File handling in C
File handling in CFile handling in C
File handling in C
 
File management
File managementFile management
File management
 
Data Structure Using C - FILES
Data Structure Using C - FILESData Structure Using C - FILES
Data Structure Using C - FILES
 
Unit5
Unit5Unit5
Unit5
 
Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
 
file_c.pdf
file_c.pdffile_c.pdf
file_c.pdf
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
 
File operations in c
File operations in cFile operations in c
File operations in c
 

Mais de Sonya Akter Rupa

Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSonya Akter Rupa
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in JavaSonya Akter Rupa
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C ProgrammingSonya Akter Rupa
 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for BangladeshSonya Akter Rupa
 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISonya Akter Rupa
 

Mais de Sonya Akter Rupa (9)

Synchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic DeviceSynchronous Counter in Digital Logic Device
Synchronous Counter in Digital Logic Device
 
Method Overloading in Java
Method Overloading in JavaMethod Overloading in Java
Method Overloading in Java
 
Enviremental Pollution
Enviremental PollutionEnviremental Pollution
Enviremental Pollution
 
Switch Case in C Programming
Switch Case in C ProgrammingSwitch Case in C Programming
Switch Case in C Programming
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
One Dimentional Array
One Dimentional ArrayOne Dimentional Array
One Dimentional Array
 
Two Dimentional Array
Two Dimentional ArrayTwo Dimentional Array
Two Dimentional Array
 
The population is resource or burden for Bangladesh
The population is resource or burden for BangladeshThe population is resource or burden for Bangladesh
The population is resource or burden for Bangladesh
 
Spherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics IISpherical Polar Coordinate System- physics II
Spherical Polar Coordinate System- physics II
 

Último

Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfsmsksolar
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Servicemeghakumariji156
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxmaisarahman1
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...HenryBriggs2
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersMairaAshraf6
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksMagic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxnuruddin69
 

Último (20)

Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 

File in C Programming

  • 1. File in C ProgrammingFile in C Programming
  • 2.
  • 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