SlideShare una empresa de Scribd logo
1 de 13
Computer Programming & Utilization
1
 The functions that we use such as scanf( ) & printf( ) are there
to read and write data. These I/O functions always use the
terminal (Keyboard and Screen) as the target place.
 These functions work where the data is small, but the entire
process becomes cumbersome and time consuming when it
comes to many real-life problems which involve large volumes
of data through terminals & due to this the entire data is lost
when either a program is terminated or computer is turned off.
 So a flexible approach was brought in, leading to the concept
of files in which data can be stored on the disks and read
whenever necessary, without destroying the data.
2
 A file is a place on the disk where a group of related data is
stored.
 Computers store files to secondary storage so that the contents
of files remain intact when a computer shuts down.
 When a computer reads a file, it copies the file from the storage
device to memory; when it writes to a file, it transfers data
from memory to the storage device.
 Two distinct ways to perform file operations in C:-
low-level I/O – Uses UNIX system calls.
high-level I/O – Uses functions in C’s standard I/O library.
3
4
Function Name Operation
fopen() Creates a new file/Opens an existing file for use.
fclose() Closes a file which has been opened for use.
getc() Reads a character from a file.
putc() Writes a character to a file.
fprintf() Writes a set of data values to a file.
fscanf() Reads a set of data values to a file.
getw() Reads an integer from file.
putw() Writes an integer from file.
fseek() Sets the position to a desired a point in the file.
ftell() Gives the correct position in the file.
rewind() Sets the position to the beginning of the file.
 Filename is a string of characters that make up a valid filename
for the operating system.
 Data structure of a file is defined as FILE in the library of
standard I/O functions definitions.
 C uses a structure called FILE (defined in stdio.h) to store the
attributes of a file. FILE is a defined data type.
 General format for defining & opening a file:-
5
FILE *fp;
fp = fopen(“filename” , “mode”);
 The first statement declares the variable fp as a “pointer to the
data type FILE”.
 The second statement opens the file filename and assigns an
identifier to the FILE type pointer fp. It also specifies the
purpose of opening this file. The mode does this job.
 Modes:-
r – Open the file for reading only.
w – Open the file for writing only.
a – Open the file for appending data to it.
6
FILE *p1, *p2;
p1 = fopen(“CPU” , “r”);
p2 = fopen(“Data” , “w”);
 Closing a file ensures that all outstanding information
associated with the file is flushed out from the buffers and all
links to the file are broken.
 Syntax for closing a file:-
 Example:-
7
fclose(file_pointer);
FILE *p1, *p2;
p1 = fopen(“cpu” , “r”);
p2 = fopen(“data” , “w”);
……………..
fclose(p1);
fclose(p2);
 getc and putc are the simplest file I/O functions. These are
analogous to getchar and putchar functions and handle one
character at a time.
 getc is used to read a character from a file that has been
opened, while putc is used to write a character to the file that
has been opened.
 Syntax for getc:-
 Syntax for putc:-
8
identifier = getc(file pointer);
putc(identifier , file pointer);
 Example:-
9
FILE *fp1, *fp2;
fp1= fopen(“input.txt” , “r”);
fp2 = fopen(“output.txt” , “w”);
char ch;
ch = getc (fp1);
putc(ch,fp2);
fclose(fp1);
fclose(fp2);
 The getw and putw are integer-oriented functions. They are
similar to getc and putc functions and are used to read and
write integer values.
 Syntax for getw:-
 Syntax for putw:-
10
getw(file pointer);
putw(integer , file pointer);
 Most compilers support functions fprintf and fscanf ,that can
handle a group of mixed data simultaneously.
 The functions fprintf and fscanf are identical to the familiar
printf and scanf functions, except of course that they work on
files.
 Syntax & Example of fprintf:-
11
fprintf(fp ,“Control String”, list);
fprintf(fp,“%s %d %f”,name,age,8);
 Syntax & Example of fscanf:-
12
fscanf(fp ,“Control String”, list);
fprintf(fp,“%s %d”,name,&quantity);
13

Más contenido relacionado

La actualidad más candente (20)

C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Files in c++
Files in c++Files in c++
Files in c++
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
File in C language
File in C languageFile in C language
File in C language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
File Handling in Python
File Handling in PythonFile Handling in Python
File Handling in Python
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Compare between pop and oop
Compare between pop and oopCompare between pop and oop
Compare between pop and oop
 
structure and union
structure and unionstructure and union
structure and union
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 

Similar a File Management in C

Similar a File Management in C (20)

File management
File managementFile management
File management
 
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
 
Unit5
Unit5Unit5
Unit5
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
Unit 8
Unit 8Unit 8
Unit 8
 
File Organization
File OrganizationFile Organization
File Organization
 
Files in C
Files in CFiles in C
Files in C
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
PPS-II UNIT-5 PPT.pptx
PPS-II  UNIT-5 PPT.pptxPPS-II  UNIT-5 PPT.pptx
PPS-II UNIT-5 PPT.pptx
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
File management
File managementFile management
File management
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
 
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDYC UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
C UNIT-5 PREPARED BY M V BRAHMANANDA REDDY
 
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
 
Unit 5 dwqb ans
Unit 5 dwqb ansUnit 5 dwqb ans
Unit 5 dwqb ans
 
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
 

Más de Paurav Shah

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithmsPaurav Shah
 
Cost and Cost Concepts
Cost and Cost ConceptsCost and Cost Concepts
Cost and Cost ConceptsPaurav Shah
 
3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses3 D (3-Dimensional) Glasses
3 D (3-Dimensional) GlassesPaurav Shah
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data StructurePaurav Shah
 
Design issues with constraints of E-R model
Design issues with constraints of E-R modelDesign issues with constraints of E-R model
Design issues with constraints of E-R modelPaurav Shah
 
Android and iOS Mobile OS
Android and iOS Mobile OSAndroid and iOS Mobile OS
Android and iOS Mobile OSPaurav Shah
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital ElectronicsPaurav Shah
 
Contributor Career Strategies
Contributor Career StrategiesContributor Career Strategies
Contributor Career StrategiesPaurav Shah
 
Semiconductor and It's Importance
Semiconductor and It's ImportanceSemiconductor and It's Importance
Semiconductor and It's ImportancePaurav Shah
 
Builiding A Good Personality
Builiding A Good PersonalityBuiliding A Good Personality
Builiding A Good PersonalityPaurav Shah
 

Más de Paurav Shah (11)

Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Cost and Cost Concepts
Cost and Cost ConceptsCost and Cost Concepts
Cost and Cost Concepts
 
3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses3 D (3-Dimensional) Glasses
3 D (3-Dimensional) Glasses
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
 
Design issues with constraints of E-R model
Design issues with constraints of E-R modelDesign issues with constraints of E-R model
Design issues with constraints of E-R model
 
Android and iOS Mobile OS
Android and iOS Mobile OSAndroid and iOS Mobile OS
Android and iOS Mobile OS
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
 
Contributor Career Strategies
Contributor Career StrategiesContributor Career Strategies
Contributor Career Strategies
 
Semiconductor and It's Importance
Semiconductor and It's ImportanceSemiconductor and It's Importance
Semiconductor and It's Importance
 
Earthing
EarthingEarthing
Earthing
 
Builiding A Good Personality
Builiding A Good PersonalityBuiliding A Good Personality
Builiding A Good Personality
 

Último

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
"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
 
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
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
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
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxNadaHaitham1
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdfKamal Acharya
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 

Último (20)

S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
"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"
 
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
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
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
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
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
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 

File Management in C

  • 1. Computer Programming & Utilization 1
  • 2.  The functions that we use such as scanf( ) & printf( ) are there to read and write data. These I/O functions always use the terminal (Keyboard and Screen) as the target place.  These functions work where the data is small, but the entire process becomes cumbersome and time consuming when it comes to many real-life problems which involve large volumes of data through terminals & due to this the entire data is lost when either a program is terminated or computer is turned off.  So a flexible approach was brought in, leading to the concept of files in which data can be stored on the disks and read whenever necessary, without destroying the data. 2
  • 3.  A file is a place on the disk where a group of related data is stored.  Computers store files to secondary storage so that the contents of files remain intact when a computer shuts down.  When a computer reads a file, it copies the file from the storage device to memory; when it writes to a file, it transfers data from memory to the storage device.  Two distinct ways to perform file operations in C:- low-level I/O – Uses UNIX system calls. high-level I/O – Uses functions in C’s standard I/O library. 3
  • 4. 4 Function Name Operation fopen() Creates a new file/Opens an existing file for use. fclose() Closes a file which has been opened for use. getc() Reads a character from a file. putc() Writes a character to a file. fprintf() Writes a set of data values to a file. fscanf() Reads a set of data values to a file. getw() Reads an integer from file. putw() Writes an integer from file. fseek() Sets the position to a desired a point in the file. ftell() Gives the correct position in the file. rewind() Sets the position to the beginning of the file.
  • 5.  Filename is a string of characters that make up a valid filename for the operating system.  Data structure of a file is defined as FILE in the library of standard I/O functions definitions.  C uses a structure called FILE (defined in stdio.h) to store the attributes of a file. FILE is a defined data type.  General format for defining & opening a file:- 5 FILE *fp; fp = fopen(“filename” , “mode”);
  • 6.  The first statement declares the variable fp as a “pointer to the data type FILE”.  The second statement opens the file filename and assigns an identifier to the FILE type pointer fp. It also specifies the purpose of opening this file. The mode does this job.  Modes:- r – Open the file for reading only. w – Open the file for writing only. a – Open the file for appending data to it. 6 FILE *p1, *p2; p1 = fopen(“CPU” , “r”); p2 = fopen(“Data” , “w”);
  • 7.  Closing a file ensures that all outstanding information associated with the file is flushed out from the buffers and all links to the file are broken.  Syntax for closing a file:-  Example:- 7 fclose(file_pointer); FILE *p1, *p2; p1 = fopen(“cpu” , “r”); p2 = fopen(“data” , “w”); …………….. fclose(p1); fclose(p2);
  • 8.  getc and putc are the simplest file I/O functions. These are analogous to getchar and putchar functions and handle one character at a time.  getc is used to read a character from a file that has been opened, while putc is used to write a character to the file that has been opened.  Syntax for getc:-  Syntax for putc:- 8 identifier = getc(file pointer); putc(identifier , file pointer);
  • 9.  Example:- 9 FILE *fp1, *fp2; fp1= fopen(“input.txt” , “r”); fp2 = fopen(“output.txt” , “w”); char ch; ch = getc (fp1); putc(ch,fp2); fclose(fp1); fclose(fp2);
  • 10.  The getw and putw are integer-oriented functions. They are similar to getc and putc functions and are used to read and write integer values.  Syntax for getw:-  Syntax for putw:- 10 getw(file pointer); putw(integer , file pointer);
  • 11.  Most compilers support functions fprintf and fscanf ,that can handle a group of mixed data simultaneously.  The functions fprintf and fscanf are identical to the familiar printf and scanf functions, except of course that they work on files.  Syntax & Example of fprintf:- 11 fprintf(fp ,“Control String”, list); fprintf(fp,“%s %d %f”,name,age,8);
  • 12.  Syntax & Example of fscanf:- 12 fscanf(fp ,“Control String”, list); fprintf(fp,“%s %d”,name,&quantity);
  • 13. 13