SlideShare a Scribd company logo
1 of 17
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

Similar to files in c ppt.ppt

PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptxSandeepbhuma1
Β 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5Vikram Nandini
Β 
Unit v
Unit vUnit v
Unit vkannaki
Β 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cpAmarjith C K
Β 
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.pdfsudhakargeruganti
Β 
Unit5
Unit5Unit5
Unit5mrecedu
Β 
File Management in C
File Management in CFile Management in C
File Management in CPaurav Shah
Β 
File handling in c
File handling in cFile handling in c
File handling in cmohit biswal
Β 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.pptyuvrajkeshri
Β 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdfSureshKalirawna
Β 
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡Ί
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡ΊC ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡Ί
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡ΊPingLun Liao
Β 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptxMehul Desai
Β 
File management
File managementFile management
File managementsumathiv9
Β 

Similar to files in c ppt.ppt (20)

PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
Β 
File handling in c
File handling in cFile handling in c
File handling in c
Β 
File in C language
File in C languageFile in C language
File in C language
Β 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
Β 
Unit v
Unit vUnit v
Unit v
Β 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
Β 
File in c
File in cFile in c
File in c
Β 
PPS-II UNIT-5 PPT.pptx
PPS-II  UNIT-5 PPT.pptxPPS-II  UNIT-5 PPT.pptx
PPS-II UNIT-5 PPT.pptx
Β 
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
Β 
File Management in C
File Management in CFile Management in C
File Management in C
Β 
File handling in c
File handling in cFile handling in c
File handling in c
Β 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
Β 
File handling-c
File handling-cFile handling-c
File handling-c
Β 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
Β 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
Β 
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡Ί
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡ΊC ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡Ί
C ζͺ”ζ‘ˆθΌΈε…₯θˆ‡θΌΈε‡Ί
Β 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
Β 
File management
File managementFile management
File management
Β 

More from Sheik Mohideen

UNIT IV RESOURCE MANAGEMENT AND SECURITY
UNIT IV RESOURCE MANAGEMENT AND SECURITYUNIT IV RESOURCE MANAGEMENT AND SECURITY
UNIT IV RESOURCE MANAGEMENT AND SECURITYSheik Mohideen
Β 
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADCS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADSheik Mohideen
Β 
Multi dimensional sketch based sip flooding detection using hellinger distance
Multi dimensional sketch based sip flooding detection using hellinger distanceMulti dimensional sketch based sip flooding detection using hellinger distance
Multi dimensional sketch based sip flooding detection using hellinger distanceSheik Mohideen
Β 

More from Sheik Mohideen (9)

UNIT IV RESOURCE MANAGEMENT AND SECURITY
UNIT IV RESOURCE MANAGEMENT AND SECURITYUNIT IV RESOURCE MANAGEMENT AND SECURITY
UNIT IV RESOURCE MANAGEMENT AND SECURITY
Β 
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOADCS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
CS2357_OOAD_CS2357_OOAD_CS2357_OOAD_CS2357_OOAD
Β 
structure.ppt
structure.pptstructure.ppt
structure.ppt
Β 
9966850
99668509966850
9966850
Β 
Mr
MrMr
Mr
Β 
2017 b.e.-cse
2017 b.e.-cse2017 b.e.-cse
2017 b.e.-cse
Β 
Multi dimensional sketch based sip flooding detection using hellinger distance
Multi dimensional sketch based sip flooding detection using hellinger distanceMulti dimensional sketch based sip flooding detection using hellinger distance
Multi dimensional sketch based sip flooding detection using hellinger distance
Β 
techcodes
techcodestechcodes
techcodes
Β 
Replica
ReplicaReplica
Replica
Β 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
Β 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
Β 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
Β 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
Β 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
Β 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
Β 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Dr. Mazin Mohamed alkathiri
Β 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
Β 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
Β 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
Β 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
Β 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
Β 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
Β 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
Β 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
Β 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
Β 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
Β 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
Β 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Β 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
Β 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
Β 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
Β 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
Β 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
Β 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
Β 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Β 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
Β 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Β 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Β 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
Β 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
Β 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Β 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Β 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
Β 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
Β 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Β 

files in c ppt.ppt

  • 1.
  • 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