SlideShare a Scribd company logo
1 of 18
INTRODUCTION TO FILE HANDLING
Presentation topic:-
Submitted by Guided by
Vikash Maurya 👨 👸
CONTENTS 👉
1⃣ What is file?
2⃣ Need of file in C programming.
3⃣ Data organization.
4⃣ File operations.
5⃣ Creating a new file by C.
6⃣ Writing, Reading and Append operation in the file.
7⃣ Closing a file.
WHAT IS FILE? 🤔
 A file is a collection of related data that a computer
treats as a single unit.
 Computer 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.
 C uses a structure called FILE (defined in stdio.h)
to store the attributes of a file.
NEED OF FILE IN C PROGRAMMING 📂
Often it is not enough to just display the data on the
screen. Because if the data is large, only few of it
can be stored and displayed on the screen. Here
memory is volatile so the contents would be lost
once the program is terminated. So if we need the
same data we need to re-enter it or regenerate the
program. And to redo the process is time wasting.
And if we would have saved it to a media where the
data can be recoverable, it would help us. This
medium is usually a ‘file’ on the disk.
DATA ORGANIZATION 💻
Before we start doing input/output let us first find out
how data is organized on the disk. Here is the
solution-
Our program
C Library
functions
OS Disk
FILE OPERATIONS 🔧
There are different operations that can be carried out
in a file.
These are:
(a) Creation of a new file.
(b) Opening an existing file.
(c) Writing to a file.
(d) Reading form a file.
(e) Closing a file.
PROGRAM TO CREATE A FILE 📣
 /* C program to create a file called emp.rec and store information
 * about a person, in terms of his name, age and salary */
 #include <stdio.h>
 #include <conio.h>
 void main()
 {
 FILE *fptr;
 char name[20];
 int age;
 float salary;
 /* open for writing */
 fptr = fopen("emp.c", "w");
 printf("Enter the name n");
 scanf("%s", name);
 fprintf(fptr, "Name = %sn", name);
 printf("Enter the agen");
 scanf("%d", &age);
 fprintf(fptr, "Age = %dn", age);
 printf("Enter the salaryn");
 scanf("%f", &salary);
 fprintf(fptr, "Salary = %.2fn", salary);
 fclose(fptr);
 }
OUTPUT 🔭
FILE
/*FOR READING A SAVED FILE*/
 #include <stdio.h>
 #include <conio.h>
 void main()
 {
 FILE *fptr;
 char a;
 fptr=fopen("emp.c","r");
 while(1)
 {
 a=fgetc(fptr);
 if(a==EOF)
 break;
 printf("%c",a);
 }
 printf("n");
 fclose(fptr);
 getch();
 }
OUTPUT 🔬
/*PROGRAM IN APPEND MODE*/
 #include <stdio.h>
 #include <conio.h>
 void main()
 {
 FILE *fptr;
 char name[20];
 int age;
 float salary;
 fptr = fopen("emp.c", “a");
 printf("Enter the name n");
 scanf("%s", name);
 fprintf(fptr, "Name = %sn", name);
 printf("Enter the agen");
 scanf("%d", &age);
 fprintf(fptr, "Age = %dn", age);
 printf("Enter the salaryn");
 scanf("%f", &salary);
 fprintf(fptr, "Salary = %.2fn", salary);
 fclose(fptr);
 }
OUTPUT 🎥
FILE
FILE OPEN MODE 📌
MORE ON FILE OPEN MODE 📡
CLOSING A FILE 🔓
 When we finish with a mode, we need to close the
file before ending the program or beginning another
mode with that same file.
 To close a file, we use fclose.
Introduction of file handling

More Related Content

What's hot

Pivotal greenplum external tables
Pivotal greenplum external tablesPivotal greenplum external tables
Pivotal greenplum external tablesRajesh Goyal
 
Presentation on files
Presentation on filesPresentation on files
Presentation on filesmallubenal
 
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유비윈도우즈 환경의 기술 서적 번역 도구 경험 공유
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유Younggun Kim
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
Python data file handling
Python data file handlingPython data file handling
Python data file handlingToniyaP1
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoopQuỳnh Phan
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/OMarc Gouw
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c languageHarish Gyanani
 
Oop bullets graphical
Oop bullets graphicalOop bullets graphical
Oop bullets graphicalswathi4crazy
 
Information Gathering
Information GatheringInformation Gathering
Information Gatheringmirojo
 
RSS feeds using Millennium data
RSS feeds using Millennium dataRSS feeds using Millennium data
RSS feeds using Millennium dataAndrew Preater
 

What's hot (17)

Pivotal greenplum external tables
Pivotal greenplum external tablesPivotal greenplum external tables
Pivotal greenplum external tables
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Presentation on files
Presentation on filesPresentation on files
Presentation on files
 
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유비윈도우즈 환경의 기술 서적 번역 도구 경험 공유
비윈도우즈 환경의 기술 서적 번역 도구 경험 공유
 
php file uploading
php file uploadingphp file uploading
php file uploading
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
Php i basic chapter 4
Php i basic chapter 4Php i basic chapter 4
Php i basic chapter 4
 
Circos
CircosCircos
Circos
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 
Class 7b: Files & File I/O
Class 7b: Files & File I/OClass 7b: Files & File I/O
Class 7b: Files & File I/O
 
Fileinc
FileincFileinc
Fileinc
 
FormatJS - JSConf Argentina
FormatJS - JSConf ArgentinaFormatJS - JSConf Argentina
FormatJS - JSConf Argentina
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
Oop bullets graphical
Oop bullets graphicalOop bullets graphical
Oop bullets graphical
 
Information Gathering
Information GatheringInformation Gathering
Information Gathering
 
RSS feeds using Millennium data
RSS feeds using Millennium dataRSS feeds using Millennium data
RSS feeds using Millennium data
 

Similar to Introduction of file handling

VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5YOGESH SINGH
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-fileDeepak Singh
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptxVishuSaini22
 
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxbanu236831
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Abdullah khawar
 
File management
File managementFile management
File managementsumathiv9
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handlingRai University
 

Similar to Introduction of file handling (20)

File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
Handling computer files
Handling computer filesHandling computer files
Handling computer files
 
data file handling
data file handlingdata file handling
data file handling
 
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_Handling in C.ppt
File_Handling in C.pptFile_Handling in C.ppt
File_Handling in C.ppt
 
File handling in cpp
File handling in cppFile handling in cpp
File handling in cpp
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
C-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptxC-FILE MANAGEMENT.pptx
C-FILE MANAGEMENT.pptx
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
File management
File managementFile management
File management
 
File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
pointer, structure ,union and intro to file handling
 pointer, structure ,union and intro to file handling pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.2 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.2 pointer, structure ,union and intro to file handling
 

More from VC Infotech

More from VC Infotech (14)

Covid-19
Covid-19Covid-19
Covid-19
 
Cyclotron
CyclotronCyclotron
Cyclotron
 
Vector
VectorVector
Vector
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
E wallet
E walletE wallet
E wallet
 
Gauss Divergence Therom
Gauss Divergence TheromGauss Divergence Therom
Gauss Divergence Therom
 
Hotspot!
Hotspot!Hotspot!
Hotspot!
 
Windows firewall
Windows firewallWindows firewall
Windows firewall
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
computer Virus
computer Virus computer Virus
computer Virus
 
Firewall protection
Firewall protectionFirewall protection
Firewall protection
 
Frindship
FrindshipFrindship
Frindship
 
Vikash maurya
Vikash mauryaVikash maurya
Vikash maurya
 
E wallet
E walletE wallet
E wallet
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Introduction of file handling

  • 1. INTRODUCTION TO FILE HANDLING Presentation topic:- Submitted by Guided by Vikash Maurya 👨 👸
  • 2. CONTENTS 👉 1⃣ What is file? 2⃣ Need of file in C programming. 3⃣ Data organization. 4⃣ File operations. 5⃣ Creating a new file by C. 6⃣ Writing, Reading and Append operation in the file. 7⃣ Closing a file.
  • 3. WHAT IS FILE? 🤔  A file is a collection of related data that a computer treats as a single unit.  Computer 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.  C uses a structure called FILE (defined in stdio.h) to store the attributes of a file.
  • 4. NEED OF FILE IN C PROGRAMMING 📂 Often it is not enough to just display the data on the screen. Because if the data is large, only few of it can be stored and displayed on the screen. Here memory is volatile so the contents would be lost once the program is terminated. So if we need the same data we need to re-enter it or regenerate the program. And to redo the process is time wasting. And if we would have saved it to a media where the data can be recoverable, it would help us. This medium is usually a ‘file’ on the disk.
  • 5. DATA ORGANIZATION 💻 Before we start doing input/output let us first find out how data is organized on the disk. Here is the solution- Our program C Library functions OS Disk
  • 6. FILE OPERATIONS 🔧 There are different operations that can be carried out in a file. These are: (a) Creation of a new file. (b) Opening an existing file. (c) Writing to a file. (d) Reading form a file. (e) Closing a file.
  • 7. PROGRAM TO CREATE A FILE 📣  /* C program to create a file called emp.rec and store information  * about a person, in terms of his name, age and salary */  #include <stdio.h>  #include <conio.h>  void main()  {  FILE *fptr;  char name[20];  int age;  float salary;  /* open for writing */  fptr = fopen("emp.c", "w");  printf("Enter the name n");  scanf("%s", name);  fprintf(fptr, "Name = %sn", name);  printf("Enter the agen");  scanf("%d", &age);  fprintf(fptr, "Age = %dn", age);  printf("Enter the salaryn");  scanf("%f", &salary);  fprintf(fptr, "Salary = %.2fn", salary);  fclose(fptr);  }
  • 10. /*FOR READING A SAVED FILE*/  #include <stdio.h>  #include <conio.h>  void main()  {  FILE *fptr;  char a;  fptr=fopen("emp.c","r");  while(1)  {  a=fgetc(fptr);  if(a==EOF)  break;  printf("%c",a);  }  printf("n");  fclose(fptr);  getch();  }
  • 12. /*PROGRAM IN APPEND MODE*/  #include <stdio.h>  #include <conio.h>  void main()  {  FILE *fptr;  char name[20];  int age;  float salary;  fptr = fopen("emp.c", “a");  printf("Enter the name n");  scanf("%s", name);  fprintf(fptr, "Name = %sn", name);  printf("Enter the agen");  scanf("%d", &age);  fprintf(fptr, "Age = %dn", age);  printf("Enter the salaryn");  scanf("%f", &salary);  fprintf(fptr, "Salary = %.2fn", salary);  fclose(fptr);  }
  • 14. FILE
  • 16. MORE ON FILE OPEN MODE 📡
  • 17. CLOSING A FILE 🔓  When we finish with a mode, we need to close the file before ending the program or beginning another mode with that same file.  To close a file, we use fclose.