SlideShare a Scribd company logo
1 of 29
Download to read offline
File Handling
• A file is a container in computer storage devices
used for storing data
Why files are needed in programming ?
• When a program is terminated, the entire data is
lost.
• Storing in a file will preserve your data even if the
program terminates.
• If we have to enter a large number of data, it will
take a lot of time to enter them all.
• If we have a file containing all the data, we can
easily access the contents of the file .
• Easy to move your data from one computer to
another without any changes
Types of Files
• Text files
• Binary files
Text Files
• Text files contain ASCII codes of digits,
alphabetic and symbols.
• Text files are the normal .txt files.
• Create text files using any simple text editors
such as Notepad
Binary files
• Binary file contains collection of bytes (0’s and 1’s).
Binary files are compiled version of text files.
• Binary files are mostly the .bin files in computer.
File Operations
• Creating a new file
• Opening an existing file
• Closing a file
• Reading from and writing information to a file
Working with files
• Need to declare a pointer of type file
FILE *fptr ;
• This declaration is needed for communication
between the file and the program.
Opening a file - for creation and edit
• Opening a file is performed using
fopen( ) function
• Function is stdio.h header file
• Syntax for opening a file in standard I/O is:
FILE *ptr ;
ptr = fopen ( “ name of file” , “filemode”);
File Opening Modes
• r : opens a text file in reading mode.
• w : opens or creates a text file in
writing mode.
• a : opens a text file in append mode. Data is
added at the end of file
• r+ : opens a text file in both reading and
writing mode. ...
• w+ : opens a text file in both reading and
writing mode.
• rb : Open for reading in binary mode.
• wb : Open for writing in binary mode.
• ab : data is added at the end of binary file
• rb+:Open for both reading and writing in
binary mode.
• wb+:Open for both reading and writing in
binary mode.
Closing a File
• File (both text and binary) should be closed
after reading/writing.
• Closing a file is performed using
the fclose() function.
• Syntax for closing file
fclose ( ptr );
ptr is a file pointer associated with the file to be
closed.
Write to a text file
#include <stdio.h>
#include <stdlib.h>
void main()
{
int num;
FILE *fptr;
ptr = fopen(“C:ECE.txt","w");
if( ptr == NULL)
{ printf("Error!");
exit(1);
}
printf("Enter num: ");
scanf("%d", &num);
fprintf( ptr, "%d“ , num);
fclose(fptr);
}
• This program takes a number from the user
and stores in the file ECE.txt.
• After compilation and executing the program,
we can see a text file ECE.txt created in C drive
of computer.
• When we open the file, we can see the integer
we entered.
•
Read from a text file
#include <stdio.h>
#include <stdlib.h>
void main()
{
int num;
FILE *ptr;
ptr = fopen ("C:ECE.txt“ , "r“ );
if ((ptr) == NULL)
{
printf("Error! opening file");
exit(1);
}
Fscanf ( ptr,"%d", &num);
printf("Value of n=%d", num);
fclose( ptr );
}
File Inbuilt Functions
fopen()
• Declaration: FILE *fopen (const char *filename, const char
*mode)
• fopen() function is used to open a file to perform operations
such as reading, writing .
• fopen() function creates a new file if the mentioned file name
does not exist.
FILE *fp;
fp=fopen (“filename”, ”‘mode”);
fprintf()
int fprintf(FILE *fp, const char *format, …);
• fprintf() function writes string into a file pointed by fp.
In a C program, we write string into a file as below.
fprintf (fp, “some data”);
fprintf (fp, “text %d”, variable_name);
fgets()
fgets function is used to read a file line by line.
fgets (buffer, size, fp);
where,
buffer – buffer to put the data in.
size – size of the buffer
fp – file pointer
putw( )
int putw( int number, FILE *fp );
• putw function is used to write an integer into
a file.
• In a C program, we can write integer value in a
file as below.
putw(i, fp);
where
i – integer value
fp – file pointer
getw()
int getw( FILE *fp );
• getw function reads an integer value from a
file pointed by fp.
• In a C program, we can read integer value
from a file as below.
getw(fp);
feof()
• feof functions is used to find the end of a file.
feof(fp);
where
fp – file pointer
fscanf()
• fscanf() function is used to read formatted
data from a file.
fscanf (fp, “%d”, &x);
Where, fp is file pointer to the data type “FILE”.
x– Integer variable
ftell()
• ftell function is used to get current position of
the file pointer.
ftell(fp);
rewind()
• rewind function is used to move file pointer
position to the beginning of the file.
rewind(fp);
Where fp is FILE pointer
fputchar()
• fputchar() function is used to write a character
on standard output/screen
fputchar(char);
where char is a character variable/value.
fgetchar( )
• fgetchar() function is used to get/read a
character from keyboard input.
fgetchar();
fseek()
• fseek() function is used to move file pointer position to the
given location.
fseek(FILE *fp, long int offset, int whence)
where,
fp – file pointer
offset – Number of bytes/characters to be offset/moved from
whence/the current file pointer position
whence – This is the current file pointer position from where
offset is added . Three constants are used to specify it :
Three constants
SEEK_SET – It moves file pointer position to the
beginning of the file.
SEEK_CUR – It moves file pointer position to
given location.
SEEK_END – It moves file pointer position to the
end of file.

More Related Content

Similar to 637225560972186380.pdf (20)

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O Linux System Programming - Buffered I/O
Linux System Programming - Buffered I/O
 
File Management
File ManagementFile Management
File Management
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
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
 
C-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.pptC-Programming Chapter 5 File-handling-C.ppt
C-Programming Chapter 5 File-handling-C.ppt
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
File operations in c
File operations in cFile operations in c
File operations in c
 
File handling in C by Faixan
File handling in C by FaixanFile handling in C by Faixan
File handling in C by Faixan
 
File management
File managementFile management
File management
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
File Handling as 08032021 (1).ppt
File Handling as 08032021 (1).pptFile Handling as 08032021 (1).ppt
File Handling as 08032021 (1).ppt
 
Engineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptxEngineering Computers L34-L35-File Handling.pptx
Engineering Computers L34-L35-File Handling.pptx
 
Module 03 File Handling in C
Module 03 File Handling in CModule 03 File Handling in C
Module 03 File Handling in C
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Files in c++
Files in c++Files in c++
Files in c++
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
File in c
File in cFile in c
File in c
 

Recently uploaded

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

637225560972186380.pdf

  • 2. • A file is a container in computer storage devices used for storing data Why files are needed in programming ? • When a program is terminated, the entire data is lost. • Storing in a file will preserve your data even if the program terminates. • If we have to enter a large number of data, it will take a lot of time to enter them all. • If we have a file containing all the data, we can easily access the contents of the file . • Easy to move your data from one computer to another without any changes
  • 3. Types of Files • Text files • Binary files Text Files • Text files contain ASCII codes of digits, alphabetic and symbols. • Text files are the normal .txt files. • Create text files using any simple text editors such as Notepad
  • 4. Binary files • Binary file contains collection of bytes (0’s and 1’s). Binary files are compiled version of text files. • Binary files are mostly the .bin files in computer.
  • 5. File Operations • Creating a new file • Opening an existing file • Closing a file • Reading from and writing information to a file
  • 6. Working with files • Need to declare a pointer of type file FILE *fptr ; • This declaration is needed for communication between the file and the program.
  • 7. Opening a file - for creation and edit • Opening a file is performed using fopen( ) function • Function is stdio.h header file • Syntax for opening a file in standard I/O is: FILE *ptr ; ptr = fopen ( “ name of file” , “filemode”);
  • 8. File Opening Modes • r : opens a text file in reading mode. • w : opens or creates a text file in writing mode. • a : opens a text file in append mode. Data is added at the end of file • r+ : opens a text file in both reading and writing mode. ... • w+ : opens a text file in both reading and writing mode.
  • 9. • rb : Open for reading in binary mode. • wb : Open for writing in binary mode. • ab : data is added at the end of binary file • rb+:Open for both reading and writing in binary mode. • wb+:Open for both reading and writing in binary mode.
  • 10. Closing a File • File (both text and binary) should be closed after reading/writing. • Closing a file is performed using the fclose() function. • Syntax for closing file fclose ( ptr ); ptr is a file pointer associated with the file to be closed.
  • 11. Write to a text file #include <stdio.h> #include <stdlib.h> void main() { int num; FILE *fptr; ptr = fopen(“C:ECE.txt","w"); if( ptr == NULL) { printf("Error!"); exit(1); }
  • 12. printf("Enter num: "); scanf("%d", &num); fprintf( ptr, "%d“ , num); fclose(fptr); }
  • 13. • This program takes a number from the user and stores in the file ECE.txt. • After compilation and executing the program, we can see a text file ECE.txt created in C drive of computer. • When we open the file, we can see the integer we entered. •
  • 14. Read from a text file #include <stdio.h> #include <stdlib.h> void main() { int num; FILE *ptr; ptr = fopen ("C:ECE.txt“ , "r“ ); if ((ptr) == NULL) { printf("Error! opening file"); exit(1); }
  • 15. Fscanf ( ptr,"%d", &num); printf("Value of n=%d", num); fclose( ptr ); }
  • 17. fopen() • Declaration: FILE *fopen (const char *filename, const char *mode) • fopen() function is used to open a file to perform operations such as reading, writing . • fopen() function creates a new file if the mentioned file name does not exist. FILE *fp; fp=fopen (“filename”, ”‘mode”);
  • 18. fprintf() int fprintf(FILE *fp, const char *format, …); • fprintf() function writes string into a file pointed by fp. In a C program, we write string into a file as below. fprintf (fp, “some data”); fprintf (fp, “text %d”, variable_name);
  • 19. fgets() fgets function is used to read a file line by line. fgets (buffer, size, fp); where, buffer – buffer to put the data in. size – size of the buffer fp – file pointer
  • 20. putw( ) int putw( int number, FILE *fp ); • putw function is used to write an integer into a file. • In a C program, we can write integer value in a file as below. putw(i, fp); where i – integer value fp – file pointer
  • 21. getw() int getw( FILE *fp ); • getw function reads an integer value from a file pointed by fp. • In a C program, we can read integer value from a file as below. getw(fp);
  • 22. feof() • feof functions is used to find the end of a file. feof(fp); where fp – file pointer
  • 23. fscanf() • fscanf() function is used to read formatted data from a file. fscanf (fp, “%d”, &x); Where, fp is file pointer to the data type “FILE”. x– Integer variable
  • 24. ftell() • ftell function is used to get current position of the file pointer. ftell(fp);
  • 25. rewind() • rewind function is used to move file pointer position to the beginning of the file. rewind(fp); Where fp is FILE pointer
  • 26. fputchar() • fputchar() function is used to write a character on standard output/screen fputchar(char); where char is a character variable/value.
  • 27. fgetchar( ) • fgetchar() function is used to get/read a character from keyboard input. fgetchar();
  • 28. fseek() • fseek() function is used to move file pointer position to the given location. fseek(FILE *fp, long int offset, int whence) where, fp – file pointer offset – Number of bytes/characters to be offset/moved from whence/the current file pointer position whence – This is the current file pointer position from where offset is added . Three constants are used to specify it :
  • 29. Three constants SEEK_SET – It moves file pointer position to the beginning of the file. SEEK_CUR – It moves file pointer position to given location. SEEK_END – It moves file pointer position to the end of file.