SlideShare a Scribd company logo
FILE MANAGEMENT in C
VIDHYA B
ASSISTANT PROFESSOR
Department of Computer Science with Data Analytics
Sri Ramakrishna College of Arts and Science
Coimbatore - 641 006
Tamil Nadu, India
1
FILES
2
Sri Ramakrishna College of Arts and Science
File -
Container for
Storing
Information
INTRODUCTION TO FILE
MANAGEMENT
• Console oriented – use
terminal (keyboard/screen)
• scanf(“%d”,&i) – read data
from keyboard
• printf(“%d”,i) – print data to
monitor
• Suitable for small volumes of
data
• Data lost when program
terminated
• Large data volumes
• E.g. physical experiments
(CERN collider), human
genome, population
records etc.
• Need for flexible
approach to store/retrieve
data
• Concept of files
3
Sri Ramakrishna College of Arts and Science
DEFINITION OF FILE
- A file is an object on a computer, stores data, information,
settings, or commands used with a computer program
- Two kinds of files in a system…
(i) Text files (ASCII) – ASCII codes of digits,
alphabets and symbols
(ii) Binary - contains collection of bytes (0’s and 1’s) and
are compiled version of text files.
4
Sri Ramakrishna College of Arts and Science
FILE OPERATIONS
 Creating a file
 Opening a file
 Closing a file
 Reading a file
 Writing in a file
5
Sri Ramakrishna College of Arts and Science
DEFINING AND OPENING FILE
To store data file in secondary memory (disc)
must specify to OS
 Filename (e.g. sort.c, input.data)
 Data structure (e.g. FILE)
 Purpose (e.g. reading, writing, appending)
6
Sri Ramakrishna College of Arts and Science
DEFINING AND OPENING FILE
String of characters that make up a valid filename for
OS
May contain two parts
 Primary
 Optional period with extension
Examples: a.out, prog.c, temp, text.out
7
Sri Ramakrishna College of Arts and Science
DEFINING A FILE
To have a way to access the files , let the program
keep track of the file being accessed
FILE - initialize an object of the type FILE
*fp - declare the pointer in order to point to the
file, to read from or to write on
fopen ("filename","mode") – file to open, with
file name and mode of opening as argument
8
Sri Ramakrishna College of Arts and Science
FILE *fp;
fp = fopen ("filename","mode");
OPENING A FILE
FILE *fp;
fp=fopen("home.txt", "r");
- The above statement will open the file
“home.txt” in read mode
9
Sri Ramakrishna College of Arts and Science
CLOSING A FILE
File must be closed as soon as all operations on it
completed
Ensures
All outstanding information associated with file flushed
out from buffers
All links to file broken
Accidental misuse of file prevented
If want to change mode of file, then first close and
open again
10
Sri Ramakrishna College of Arts and Science
CLOSING A FILE
Syntax: fclose(file_pointer);
Example:
FILE *p1, *p2;
p1 = fopen(“INPUT.txt”, “r”);
p2 =fopen(“OUTPUT.txt”, “w”);
……..
……..
fclose(p1);
fclose(p2);
pointer can be reused after closing
11
Sri Ramakrishna College of Arts and Science
MODES OF FILE OPERATION
12
Sri Ramakrishna College of Arts and Science
Mode Description
r Opens an existing text file for reading purpose
w Opens a text file for writing. If it does not exist,
then a new file is created
a Opens a text file for writing in appending mode.
If it does not exist, then a new file is created
MODES OF FILE OPERATION
13
Sri Ramakrishna College of Arts and Science
Mode Description
r+ Opens a text file for both reading and writing
w+ Opens a text file for both reading and writing. It
first truncates the file to zero length if it exists,
otherwise creates a file if it does not exist.
a+ Opens a text file for both reading and writing. It
creates the file if it does not exist. The reading
will start from the beginning but writing can only
be appended.
REFERENCES
14
Sri Ramakrishna College of Arts and Science
Programming in ANSI C
by
E. Balagurusamy.

More Related Content

Similar to unit 5-files.pptx

Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
Mehul Desai
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
Anil Dutt
 
File management
File managementFile management
File management
lalithambiga kamaraj
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
Gaurav Garg
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
yndaravind
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
Md. Imran Hossain Showrov
 
Handout#01
Handout#01Handout#01
Handout#01
Sunita Milind Dol
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
YOGESH SINGH
 
File management
File managementFile management
File management
sumathiv9
 
File handling in C
File handling in CFile handling in C
File handling in C
Kamal Acharya
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
Hemantha Kulathilake
 
File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
eShikshak
 
file handling1
file handling1file handling1
file handling1
student
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Unit5
Unit5Unit5
Unit5
mrecedu
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
Ananthi Palanisamy
 
File management in C++
File management in C++File management in C++
File management in C++
apoorvaverma33
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
ManasaPJ1
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 

Similar to unit 5-files.pptx (20)

Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
 
File management
File managementFile management
File management
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
Handout#01
Handout#01Handout#01
Handout#01
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
File management
File managementFile management
File management
 
File handling in C
File handling in CFile handling in C
File handling in C
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
file handling1
file handling1file handling1
file handling1
 
File in C language
File in C languageFile in C language
File in C language
 
Unit5
Unit5Unit5
Unit5
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
File management in C++
File management in C++File management in C++
File management in C++
 
MODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptxMODULE 3.1 updated-18cs56.pptx
MODULE 3.1 updated-18cs56.pptx
 
File Handling
File HandlingFile Handling
File Handling
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
Celine George
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17How to Predict Vendor Bill Product in Odoo 17
How to Predict Vendor Bill Product in Odoo 17
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 

unit 5-files.pptx

  • 1. FILE MANAGEMENT in C VIDHYA B ASSISTANT PROFESSOR Department of Computer Science with Data Analytics Sri Ramakrishna College of Arts and Science Coimbatore - 641 006 Tamil Nadu, India 1
  • 2. FILES 2 Sri Ramakrishna College of Arts and Science File - Container for Storing Information
  • 3. INTRODUCTION TO FILE MANAGEMENT • Console oriented – use terminal (keyboard/screen) • scanf(“%d”,&i) – read data from keyboard • printf(“%d”,i) – print data to monitor • Suitable for small volumes of data • Data lost when program terminated • Large data volumes • E.g. physical experiments (CERN collider), human genome, population records etc. • Need for flexible approach to store/retrieve data • Concept of files 3 Sri Ramakrishna College of Arts and Science
  • 4. DEFINITION OF FILE - A file is an object on a computer, stores data, information, settings, or commands used with a computer program - Two kinds of files in a system… (i) Text files (ASCII) – ASCII codes of digits, alphabets and symbols (ii) Binary - contains collection of bytes (0’s and 1’s) and are compiled version of text files. 4 Sri Ramakrishna College of Arts and Science
  • 5. FILE OPERATIONS  Creating a file  Opening a file  Closing a file  Reading a file  Writing in a file 5 Sri Ramakrishna College of Arts and Science
  • 6. DEFINING AND OPENING FILE To store data file in secondary memory (disc) must specify to OS  Filename (e.g. sort.c, input.data)  Data structure (e.g. FILE)  Purpose (e.g. reading, writing, appending) 6 Sri Ramakrishna College of Arts and Science
  • 7. DEFINING AND OPENING FILE String of characters that make up a valid filename for OS May contain two parts  Primary  Optional period with extension Examples: a.out, prog.c, temp, text.out 7 Sri Ramakrishna College of Arts and Science
  • 8. DEFINING A FILE To have a way to access the files , let the program keep track of the file being accessed FILE - initialize an object of the type FILE *fp - declare the pointer in order to point to the file, to read from or to write on fopen ("filename","mode") – file to open, with file name and mode of opening as argument 8 Sri Ramakrishna College of Arts and Science FILE *fp; fp = fopen ("filename","mode");
  • 9. OPENING A FILE FILE *fp; fp=fopen("home.txt", "r"); - The above statement will open the file “home.txt” in read mode 9 Sri Ramakrishna College of Arts and Science
  • 10. CLOSING A FILE File must be closed as soon as all operations on it completed Ensures All outstanding information associated with file flushed out from buffers All links to file broken Accidental misuse of file prevented If want to change mode of file, then first close and open again 10 Sri Ramakrishna College of Arts and Science
  • 11. CLOSING A FILE Syntax: fclose(file_pointer); Example: FILE *p1, *p2; p1 = fopen(“INPUT.txt”, “r”); p2 =fopen(“OUTPUT.txt”, “w”); …….. …….. fclose(p1); fclose(p2); pointer can be reused after closing 11 Sri Ramakrishna College of Arts and Science
  • 12. MODES OF FILE OPERATION 12 Sri Ramakrishna College of Arts and Science Mode Description r Opens an existing text file for reading purpose w Opens a text file for writing. If it does not exist, then a new file is created a Opens a text file for writing in appending mode. If it does not exist, then a new file is created
  • 13. MODES OF FILE OPERATION 13 Sri Ramakrishna College of Arts and Science Mode Description r+ Opens a text file for both reading and writing w+ Opens a text file for both reading and writing. It first truncates the file to zero length if it exists, otherwise creates a file if it does not exist. a+ Opens a text file for both reading and writing. It creates the file if it does not exist. The reading will start from the beginning but writing can only be appended.
  • 14. REFERENCES 14 Sri Ramakrishna College of Arts and Science Programming in ANSI C by E. Balagurusamy.