SlideShare a Scribd company logo
presentation_files_1451938150_140676.ppt
Session Objectives
Explain files
Discuss text File and binary File
Use basic file Operations & functions
Explain file pointer
Discuss current active pointer
Explain Formatted/Unformatted I/O Statements in File
Define the term “Preprocessor”
Files
A file may be anything from a disk file to a terminal or a printer.
All files are automatically closed when the program, using them,
terminates, normally by main() returning to the operating system
or by a call to exit().
Files are not closed when a program crashes
A file is associated with a stream by performing an open operation
and is disassociated from a stream by a close operation.
File :
A file is a place on the disk where a group of related data is stored simply
defined as “Collection of related information”
Types of Files:
1. Text File (or) Sequential File
2. Binary File (or) Random File
Text File :
It is a Sequence of characters. It can be organised into lines terminated by a
newline character.
Binary File :
It is a Sequence of Bytes with one-to-one correspondence to those in the
external device, that is there are no character translations.
Also the number of bytes written (or read) is the same as the number on
the external device.
It do not have any flags to indicate the end of the file. It can be determined
by the size of the file.
Basic file operations
 Naming a file
 Opening a file
 Reading data from a file
 Writing data to a file
 Closing a file
Function
Name
Operation
fopen() Creates a new file
Opens an existing file
fclose() Closes a file which has been opened
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 from a file
getw() Reads an integer from a file
putw() Writes an integer to a file
fseek() Sets the position to a desired point in the file
ftell() Gives the current position in the file(bytes)
rewind() Set the position to the begining of the file
It is a pointer to a structure which contains the
information about the file
FILE *file pointername;
FILE *fp;
FILE pointername = fopen(“filename”, “file mode”);
fp=fopen(“emp.dat”,”w”);
Mode Name Meaning
w Open a text file for Writing
r Open a text file for Reading
a Append to a text file
rb Open a binary(random) file for reading
wb Create a binary(random) file for Writing
ab Append to a binary(random) file
r+ Open a text file for Read/Write
w+ Create a text file for Read/Write
a+ Append or create a text file for Read/Write
r+b Open a binary(random) file for read/write
w+b Create a binary(random) file for read/write
a+b Append a binary(random) file for read/write
fclose(filepointer name);
fclose(fp);
Reading a character
The fgetc() function is used for reading characters from a file
opened in read mode, using fopen().
Syntax :
Writing a character
The function used for writing characters to a file, that was
previously opened using fopen(), is fputc().
Syntax :
String Input / Output
fputs() and fgets(), which write and read character strings to
and from disk file.
The Syntax for the above functions are -
fprintf() and fscanf()
These functions are similar to printf() and scanf() except that
they operate with files.
Syntax
int fprintf(FILE *fp, const char *control_string, …);
int fscanf(FILE *fp, const char *control_string, …);
The rewind() function resets the file position indicator to the
beginning of the file.
rewind() function
The syntax for rewind() is :
The prototype for the rewind() is available in stdio.h
Using feof()
When a file is opened for binary input, an integer value
equal to the EOF (End Of File) may be read.
The input routine will indicate an EOF in such a case, even
though the end of file has not reached.
The Syntax of this Function is :
Current File Pointer Position
In order to keep track of the position where I/O
operations take place a pointer is maintained in the file
structure.
The current location of the current active pointer can be
found with the help of the ftell() function
Setting Current File Pointer Position
The fseek() function repositions the filepointer by a
specified number of bytes from the start, the current
position or the end of the stream depending upon the
position specified in the fseek() function.
The Syntax of the fseek() function is -
Here the offset is the number of bytes beyond the file location
given by origin.
Setting Current File Pointer Position
The origin indicates the starting position of the search and
must have the value of either 0 ,1 or 2.
Origin File Location
SEEK_SET or 0 Beginning of file
SEEK_CUR or 1 Current file pointer position
SEEK_END or 2 End of file
The fread() and fwrite() function
The Syntax for these functions are -
size_t fread(void *buffer, size_t num_bytes, size_t count FILE *fp);
size_t fwrite(const void *buffer, size_t num_bytes, size_t count FILE *fp);
Used to read and write an entire block of data to and from
a file

More Related Content

PPTX
File Handling ppt.pptx shjd dbkd z bdjdb d
ssusere1e8b7
 
PPTX
Programming C- File Handling , File Operation
svkarthik86
 
PDF
FILES IN C
yndaravind
 
PDF
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
sangeeta borde
 
PPTX
Python data file handling
ToniyaP1
 
DOCX
Unit 8
Keerthi Mutyala
 
PPTX
File handling in c
aakanksha s
 
File Handling ppt.pptx shjd dbkd z bdjdb d
ssusere1e8b7
 
Programming C- File Handling , File Operation
svkarthik86
 
FILES IN C
yndaravind
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
sangeeta borde
 
Python data file handling
ToniyaP1
 
File handling in c
aakanksha s
 

Similar to presentation_files_1451938150_140676.ppt (20)

DOCX
Unit 5 dwqb ans
Sowri Rajan
 
PPTX
File Organization
RAMPRAKASH REDDY ARAVA
 
PPTX
PPS PPT 2.pptx
Sandeepbhuma1
 
PPT
File handling in c
David Livingston J
 
PPTX
File in C language
Manash Kumar Mondal
 
PPTX
C Programming Unit-5
Vikram Nandini
 
DOC
Unit v
kannaki
 
PDF
Module 5 file cp
Amarjith C K
 
PPT
File in c
Prabhu Govind
 
PPTX
PPS-II UNIT-5 PPT.pptx
VenkataRangaRaoKommi1
 
PPTX
File management
lalithambiga kamaraj
 
PDF
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
PPT
Unit5
mrecedu
 
PPT
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
PPTX
File Management in C
Paurav Shah
 
PPTX
want to learn files,then just use this ppt to learn
nalluribalaji157
 
PPTX
File handling in c
mohit biswal
 
PPTX
FILE HANDLING.pptx
kendriyavidyalayano24
 
PPT
File handling-c
CGC Technical campus,Mohali
 
PPT
file_handling_in_c.ppt
yuvrajkeshri
 
Unit 5 dwqb ans
Sowri Rajan
 
File Organization
RAMPRAKASH REDDY ARAVA
 
PPS PPT 2.pptx
Sandeepbhuma1
 
File handling in c
David Livingston J
 
File in C language
Manash Kumar Mondal
 
C Programming Unit-5
Vikram Nandini
 
Unit v
kannaki
 
Module 5 file cp
Amarjith C K
 
File in c
Prabhu Govind
 
PPS-II UNIT-5 PPT.pptx
VenkataRangaRaoKommi1
 
File management
lalithambiga kamaraj
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
Unit5
mrecedu
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
File Management in C
Paurav Shah
 
want to learn files,then just use this ppt to learn
nalluribalaji157
 
File handling in c
mohit biswal
 
FILE HANDLING.pptx
kendriyavidyalayano24
 
file_handling_in_c.ppt
yuvrajkeshri
 

More from ansariparveen06 (20)

PPT
Preprocessing of data mining process.ppt
ansariparveen06
 
PPT
8. Ozone and Environmental issue and solution.ppt
ansariparveen06
 
PPTX
ALP intro assembly language programing.pptx
ansariparveen06
 
PPT
cpphtp9_Exception handling in c++ .ppt
ansariparveen06
 
PPT
introduction to javascript concepts .ppt
ansariparveen06
 
PPT
java multi threading and synchronisation.ppt
ansariparveen06
 
PPTX
Environmental studies part2 bscit sem2.pptx
ansariparveen06
 
PPTX
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
ansariparveen06
 
PPT
exception-handling-in-java programming.ppt
ansariparveen06
 
PPTX
brief introduction to core java programming.pptx
ansariparveen06
 
PPTX
Module1 evs Environmental Pollution.pptx
ansariparveen06
 
PPTX
Internet_Banking e commerce in banking.pptx
ansariparveen06
 
PPTX
UNIT1 Decision Support System in BI.pptx
ansariparveen06
 
PPT
logic gate based on discrete mathematics.ppt
ansariparveen06
 
PPTX
Overview on how to Disciplining in life .pptx
ansariparveen06
 
PPT
presentation on java server pages vs servlet.ppt
ansariparveen06
 
PPT
Introduction to Java Servlets and JSP (1).ppt
ansariparveen06
 
PPTX
enterprise java - introduction to servlet.pptx
ansariparveen06
 
PPTX
Introduction to Operating - Systems.pptx
ansariparveen06
 
PDF
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 
Preprocessing of data mining process.ppt
ansariparveen06
 
8. Ozone and Environmental issue and solution.ppt
ansariparveen06
 
ALP intro assembly language programing.pptx
ansariparveen06
 
cpphtp9_Exception handling in c++ .ppt
ansariparveen06
 
introduction to javascript concepts .ppt
ansariparveen06
 
java multi threading and synchronisation.ppt
ansariparveen06
 
Environmental studies part2 bscit sem2.pptx
ansariparveen06
 
ENVIRONMENTAL STUDIES FYBSCIT SEM 2.pptx
ansariparveen06
 
exception-handling-in-java programming.ppt
ansariparveen06
 
brief introduction to core java programming.pptx
ansariparveen06
 
Module1 evs Environmental Pollution.pptx
ansariparveen06
 
Internet_Banking e commerce in banking.pptx
ansariparveen06
 
UNIT1 Decision Support System in BI.pptx
ansariparveen06
 
logic gate based on discrete mathematics.ppt
ansariparveen06
 
Overview on how to Disciplining in life .pptx
ansariparveen06
 
presentation on java server pages vs servlet.ppt
ansariparveen06
 
Introduction to Java Servlets and JSP (1).ppt
ansariparveen06
 
enterprise java - introduction to servlet.pptx
ansariparveen06
 
Introduction to Operating - Systems.pptx
ansariparveen06
 
Advanced Web Programming_UNIT_1_NewSyllabus.pdf
ansariparveen06
 

Recently uploaded (20)

PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Basics and rules of probability with real-life uses
ravatkaran694
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
CDH. pptx
AneetaSharma15
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
How to Apply for a Job From Odoo 18 Website
Celine George
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Basics and rules of probability with real-life uses
ravatkaran694
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
CDH. pptx
AneetaSharma15
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
How to Apply for a Job From Odoo 18 Website
Celine George
 

presentation_files_1451938150_140676.ppt

  • 2. Session Objectives Explain files Discuss text File and binary File Use basic file Operations & functions Explain file pointer Discuss current active pointer Explain Formatted/Unformatted I/O Statements in File Define the term “Preprocessor”
  • 3. Files A file may be anything from a disk file to a terminal or a printer. All files are automatically closed when the program, using them, terminates, normally by main() returning to the operating system or by a call to exit(). Files are not closed when a program crashes A file is associated with a stream by performing an open operation and is disassociated from a stream by a close operation.
  • 4. File : A file is a place on the disk where a group of related data is stored simply defined as “Collection of related information” Types of Files: 1. Text File (or) Sequential File 2. Binary File (or) Random File Text File : It is a Sequence of characters. It can be organised into lines terminated by a newline character. Binary File : It is a Sequence of Bytes with one-to-one correspondence to those in the external device, that is there are no character translations. Also the number of bytes written (or read) is the same as the number on the external device. It do not have any flags to indicate the end of the file. It can be determined by the size of the file.
  • 5. Basic file operations  Naming a file  Opening a file  Reading data from a file  Writing data to a file  Closing a file
  • 6. Function Name Operation fopen() Creates a new file Opens an existing file fclose() Closes a file which has been opened 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 from a file getw() Reads an integer from a file putw() Writes an integer to a file fseek() Sets the position to a desired point in the file ftell() Gives the current position in the file(bytes) rewind() Set the position to the begining of the file
  • 7. It is a pointer to a structure which contains the information about the file FILE *file pointername; FILE *fp; FILE pointername = fopen(“filename”, “file mode”); fp=fopen(“emp.dat”,”w”);
  • 8. Mode Name Meaning w Open a text file for Writing r Open a text file for Reading a Append to a text file rb Open a binary(random) file for reading wb Create a binary(random) file for Writing ab Append to a binary(random) file r+ Open a text file for Read/Write w+ Create a text file for Read/Write a+ Append or create a text file for Read/Write r+b Open a binary(random) file for read/write w+b Create a binary(random) file for read/write a+b Append a binary(random) file for read/write fclose(filepointer name); fclose(fp);
  • 9. Reading a character The fgetc() function is used for reading characters from a file opened in read mode, using fopen(). Syntax : Writing a character The function used for writing characters to a file, that was previously opened using fopen(), is fputc(). Syntax :
  • 10. String Input / Output fputs() and fgets(), which write and read character strings to and from disk file. The Syntax for the above functions are -
  • 11. fprintf() and fscanf() These functions are similar to printf() and scanf() except that they operate with files. Syntax int fprintf(FILE *fp, const char *control_string, …); int fscanf(FILE *fp, const char *control_string, …);
  • 12. The rewind() function resets the file position indicator to the beginning of the file. rewind() function The syntax for rewind() is : The prototype for the rewind() is available in stdio.h
  • 13. Using feof() When a file is opened for binary input, an integer value equal to the EOF (End Of File) may be read. The input routine will indicate an EOF in such a case, even though the end of file has not reached. The Syntax of this Function is :
  • 14. Current File Pointer Position In order to keep track of the position where I/O operations take place a pointer is maintained in the file structure. The current location of the current active pointer can be found with the help of the ftell() function
  • 15. Setting Current File Pointer Position The fseek() function repositions the filepointer by a specified number of bytes from the start, the current position or the end of the stream depending upon the position specified in the fseek() function. The Syntax of the fseek() function is - Here the offset is the number of bytes beyond the file location given by origin.
  • 16. Setting Current File Pointer Position The origin indicates the starting position of the search and must have the value of either 0 ,1 or 2. Origin File Location SEEK_SET or 0 Beginning of file SEEK_CUR or 1 Current file pointer position SEEK_END or 2 End of file
  • 17. The fread() and fwrite() function The Syntax for these functions are - size_t fread(void *buffer, size_t num_bytes, size_t count FILE *fp); size_t fwrite(const void *buffer, size_t num_bytes, size_t count FILE *fp); Used to read and write an entire block of data to and from a file