SlideShare a Scribd company logo
FILE MANAGEMENT
A File can be used to store a large volume of persistent data. Like many other
languages 'C' provides following file management functions,
Creation of a file
Opening a file
Reading a file
Writing to a file
Closing a file
Following are the most important file management functions available in 'C,'
Function purpose
•fopen () Creating a file or opening an existing file
•fclose () Closing a file
•fprintf () Writing a block of data to a file
•fscanf () Reading a block data from a file
•getc () Reads a single character from a file
•putc () Writes a single character to a file
•getw () Reads an integer from a file
•putw () Writing an integer to a file
•fseek () Sets the position of a file pointer to a specified location
•ftell () Returns the current position of a file pointer
•rewind () Sets the file pointer at the beginning of a file
Whenever you want to work with a file, the first step is to create a
file.
A file is nothing but space in a memory where data is stored.
To create a file in a 'C' program following syntax is used,
FILE *fp;
fp = fopen ("file_name", "mode");
In the above syntax, the file is a data structure which is defined in the
standard library.
How to Create a File
•fopen is a standard function which is used to open a file.
•If the file is not present on the system, then it is created and then
opened.
•If a file is already present on the system, then it is directly
opened using this function.
•fp is a file pointer which points to the type file.
•Whenever you open or create a file, you have to specify what
you are going to do with the file.
•A file in 'C' programming can be created or opened for
reading/writing purposes.
• A mode is used to specify whether you want to open a file for
any of the below-given purposes.
Following are the different types of modes in 'C' programming which can be used while working with a
file.
File Mode Description
r Open a file for reading. If a file is in reading mode, then no data is deleted if a file is already
present on a system.
w Open a file for writing. If a file is in writing mode, then a new file is created if a file doesn't exist
at all. If a file is already present on a system, then all the data inside the file is truncated, and it
is opened for writing purposes.
a Open a file in append mode. If a file is in append mode, then the file is opened. The content
within the file doesn't change.
r+ open for reading and writing from beginning
w+ open for reading and writing, overwriting a file
a+ open for reading and writing, appending to file
In the given syntax, the filename and the mode are specified as strings hence they must always be
enclosed within double quotes.
EXAMPLE
#include <stdio.h>
int main()
{
FILE *fp;
fp = fopen ("data.txt", "w");
}
Output:
File is created in the same folder where you have saved your code.
You can specify the path where you want to create your file
#include <stdio.h>
int main() {
FILE *fp;
fp = fopen ("D://data.txt", "w");
}
How to Close a file
•One should always close a file whenever the operations on file are over. It means the
contents and links to the file are terminated.
•This prevents accidental damage to the file.
•'C' provides the fclose function to perform file closing operation. The syntax of fclose is
as follows,
fclose (file_pointer);
Example:
FILE *fp;
fp = fopen ("data.txt", "r");
fclose (fp);
FILE I/O Operations
When a file opened, we can read data stored in the file or write new data onto it depending on the mode
of opening standard library supports a good number of functions which can be used for performing I/O
operations. These functions are referred to as file I/O functions.
File I/O functions are broadly classified into two types:
1. High level files I/O functions
2. Low level files I/O functions
•High level file I/O functions are basically C standard library functions and are easy to use.
•Most of the C programs handling files use these because of their simple nature.
•Low level file I/O functions are file related system calls of the underlying operating system.
•These are relatively more complex in nature when compared to high level file I/O functions but efficient in
nature.
• fputc() and fgetc()-Character-oriented file I/O functions fputs() and fgets()-String-oriented file I/O
functions
High level file I/O functions can be further classified into the following two types:
1. Unformatted file I/O functions
2. Low level files I/O functions
•Unformatted file I/O functions
fputc() and fgetc()-Character-oriented file I/O functions
fputs() and fgets()-String-oriented file I/O functions
• Formatted file I/O functions
fprint() and fscanf()-Mixed data-oriented file I/O functions
Command Line ArgumentsIn C it is possible to accept command line arguments.
Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux, and
are passed in to the program from the operating system.
To establish the data communication between a calling function and a called function.
It is done through arguments; a calling function passes inputs to a called function, which perform required manipulations.
To display the contents of emp.dat, we use the following command:
C:>type emp.dat
here type is the program file name (executable) and emp.dat is the input file, the contents of which are displayed
To make main() of a program take command line arguments, the function header will have the following form:
void main(int argc,char *argv[])
Here, argc and argv [] are the formal arguments, which provide mechanism for collecting the arguments given at command
line when the program is launched for execution.
SUMATHI V
ASSITANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATIONS
SRI RAMAKRISHNA COLLEGE OF ARTS AND SCIENCE
COIMBATORE-641006
TAMILNADU,INDIA

More Related Content

What's hot

File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
vampugani
 
File Management
File ManagementFile Management
File Management
Mike Cummins
 
File Management
File ManagementFile Management
File Management
Judy Ann Casuco
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
Dhrumil Panchal
 
File structures
File structuresFile structures
File structures
Shyam Kumar
 
File Management
File ManagementFile Management
File Management
spickul
 
Files concepts.53
Files concepts.53Files concepts.53
Files concepts.53myrajendra
 
File management
File management File management
File management
Abenezer Abiti
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File Management
Damian T. Gordon
 
Types of files
Types of filesTypes of files
Types of files
Amar Jukuntla
 
File management
File managementFile management
File managementMohd Arif
 
File management
File managementFile management
File management
Vishal Singh
 
File system Os
File system OsFile system Os
File system Os
Nehal Naik
 
File management
File managementFile management
File management
Dr. Ahmed Al Zaidy
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating systemtittuajay
 
File System Implementation
File System ImplementationFile System Implementation
File System Implementation
Abhishek Pachisia
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
cois201.ut
 
ITFT_File system interface in Operating System
ITFT_File system interface in Operating SystemITFT_File system interface in Operating System
ITFT_File system interface in Operating System
Sneh Prabha
 
File System Interface
File System InterfaceFile System Interface
File System Interface
chandinisanz
 

What's hot (19)

File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
 
File Management
File ManagementFile Management
File Management
 
File Management
File ManagementFile Management
File Management
 
File Management – File Concept, access methods, File types and File Operation
File Management – File Concept, access methods,  File types and File OperationFile Management – File Concept, access methods,  File types and File Operation
File Management – File Concept, access methods, File types and File Operation
 
File structures
File structuresFile structures
File structures
 
File Management
File ManagementFile Management
File Management
 
Files concepts.53
Files concepts.53Files concepts.53
Files concepts.53
 
File management
File management File management
File management
 
Operating Systems - File Management
Operating Systems -  File ManagementOperating Systems -  File Management
Operating Systems - File Management
 
Types of files
Types of filesTypes of files
Types of files
 
File management
File managementFile management
File management
 
File management
File managementFile management
File management
 
File system Os
File system OsFile system Os
File system Os
 
File management
File managementFile management
File management
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating system
 
File System Implementation
File System ImplementationFile System Implementation
File System Implementation
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
ITFT_File system interface in Operating System
ITFT_File system interface in Operating SystemITFT_File system interface in Operating System
ITFT_File system interface in Operating System
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 

Similar to 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
sudhakargeruganti
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
YOGESH SINGH
 
file_c.pdf
file_c.pdffile_c.pdf
file_c.pdf
Osmania University
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
File Handling
File HandlingFile Handling
File Handling
AlgeronTongdoTopi
 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
SureshKalirawna
 
File handling C program
File handling C programFile handling C program
File handling C program
Thesis Scientist Private Limited
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
Prerna Sharma
 
File handing in C
File handing in CFile handing in C
File handing in C
shrishcg
 
File management
File managementFile management
File management
lalithambiga kamaraj
 
File mangement
File mangementFile mangement
File mangement
Jigarthacker
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
Hemantha Kulathilake
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
armaansohail9356
 
Programming in C
Programming in CProgramming in C
Programming in C
MalathiNagarajan20
 
Handout#01
Handout#01Handout#01
Handout#01
Sunita Milind Dol
 
File management
File managementFile management
File management
AnishaThakkar2
 
File Management in C
File Management in CFile Management in C
File Management in C
Paurav Shah
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
Ashim Lamichhane
 

Similar to File management (20)

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
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
file_c.pdf
file_c.pdffile_c.pdf
file_c.pdf
 
File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
637225560972186380.pdf
637225560972186380.pdf637225560972186380.pdf
637225560972186380.pdf
 
File handling C program
File handling C programFile handling C program
File handling C program
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
 
File handing in C
File handing in CFile handing in C
File handing in C
 
File management
File managementFile management
File management
 
File mangement
File mangementFile mangement
File mangement
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Handout#01
Handout#01Handout#01
Handout#01
 
File operations in c
File operations in cFile operations in c
File operations in c
 
File management
File managementFile management
File management
 
File Management in C
File Management in CFile Management in C
File Management in C
 
Unit 8
Unit 8Unit 8
Unit 8
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 

File management

  • 2. A File can be used to store a large volume of persistent data. Like many other languages 'C' provides following file management functions, Creation of a file Opening a file Reading a file Writing to a file Closing a file
  • 3. Following are the most important file management functions available in 'C,' Function purpose •fopen () Creating a file or opening an existing file •fclose () Closing a file •fprintf () Writing a block of data to a file •fscanf () Reading a block data from a file •getc () Reads a single character from a file •putc () Writes a single character to a file •getw () Reads an integer from a file •putw () Writing an integer to a file •fseek () Sets the position of a file pointer to a specified location •ftell () Returns the current position of a file pointer •rewind () Sets the file pointer at the beginning of a file
  • 4. Whenever you want to work with a file, the first step is to create a file. A file is nothing but space in a memory where data is stored. To create a file in a 'C' program following syntax is used, FILE *fp; fp = fopen ("file_name", "mode"); In the above syntax, the file is a data structure which is defined in the standard library. How to Create a File
  • 5. •fopen is a standard function which is used to open a file. •If the file is not present on the system, then it is created and then opened. •If a file is already present on the system, then it is directly opened using this function. •fp is a file pointer which points to the type file. •Whenever you open or create a file, you have to specify what you are going to do with the file. •A file in 'C' programming can be created or opened for reading/writing purposes. • A mode is used to specify whether you want to open a file for any of the below-given purposes.
  • 6. Following are the different types of modes in 'C' programming which can be used while working with a file. File Mode Description r Open a file for reading. If a file is in reading mode, then no data is deleted if a file is already present on a system. w Open a file for writing. If a file is in writing mode, then a new file is created if a file doesn't exist at all. If a file is already present on a system, then all the data inside the file is truncated, and it is opened for writing purposes. a Open a file in append mode. If a file is in append mode, then the file is opened. The content within the file doesn't change. r+ open for reading and writing from beginning w+ open for reading and writing, overwriting a file a+ open for reading and writing, appending to file In the given syntax, the filename and the mode are specified as strings hence they must always be enclosed within double quotes.
  • 7. EXAMPLE #include <stdio.h> int main() { FILE *fp; fp = fopen ("data.txt", "w"); } Output: File is created in the same folder where you have saved your code. You can specify the path where you want to create your file #include <stdio.h> int main() { FILE *fp; fp = fopen ("D://data.txt", "w"); }
  • 8. How to Close a file •One should always close a file whenever the operations on file are over. It means the contents and links to the file are terminated. •This prevents accidental damage to the file. •'C' provides the fclose function to perform file closing operation. The syntax of fclose is as follows, fclose (file_pointer); Example: FILE *fp; fp = fopen ("data.txt", "r"); fclose (fp);
  • 9. FILE I/O Operations When a file opened, we can read data stored in the file or write new data onto it depending on the mode of opening standard library supports a good number of functions which can be used for performing I/O operations. These functions are referred to as file I/O functions. File I/O functions are broadly classified into two types: 1. High level files I/O functions 2. Low level files I/O functions •High level file I/O functions are basically C standard library functions and are easy to use. •Most of the C programs handling files use these because of their simple nature. •Low level file I/O functions are file related system calls of the underlying operating system. •These are relatively more complex in nature when compared to high level file I/O functions but efficient in nature. • fputc() and fgetc()-Character-oriented file I/O functions fputs() and fgets()-String-oriented file I/O functions
  • 10. High level file I/O functions can be further classified into the following two types: 1. Unformatted file I/O functions 2. Low level files I/O functions •Unformatted file I/O functions fputc() and fgetc()-Character-oriented file I/O functions fputs() and fgets()-String-oriented file I/O functions • Formatted file I/O functions fprint() and fscanf()-Mixed data-oriented file I/O functions
  • 11. Command Line ArgumentsIn C it is possible to accept command line arguments. Command-line arguments are given after the name of a program in command-line operating systems like DOS or Linux, and are passed in to the program from the operating system. To establish the data communication between a calling function and a called function. It is done through arguments; a calling function passes inputs to a called function, which perform required manipulations. To display the contents of emp.dat, we use the following command: C:>type emp.dat here type is the program file name (executable) and emp.dat is the input file, the contents of which are displayed To make main() of a program take command line arguments, the function header will have the following form: void main(int argc,char *argv[]) Here, argc and argv [] are the formal arguments, which provide mechanism for collecting the arguments given at command line when the program is launched for execution.
  • 12. SUMATHI V ASSITANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATIONS SRI RAMAKRISHNA COLLEGE OF ARTS AND SCIENCE COIMBATORE-641006 TAMILNADU,INDIA