SlideShare a Scribd company logo
1 of 16
KURUVA KARUN
PGT COMP SCIENCE
KVNO.2 VASCO
BANGALORE REGION
Understanding the basic concept of file handling.
Types of files.
Functions associated to operate on binary files.
Deleting a record from binary file.
2All rights reserved
 Computer programs are associated to work
with files as it helps in storing data &
information permanently.
 File - itself a bunch of bytes stored on some
storage devices.
 In C++ this is achieved through a component
header file called fstream.h
 The I/O library manages two aspects- as
interface and for transfer of data.
 The library predefine a set of operations for
all file related handling through certain
classes.
 stream is a general term used to name flow of
data.
Streams act as an interface between files and
programs.
A Stream is sequence of bytes.
They represent as a sequence of bytes and
deals with the flow of data.
Every stream is associated with a class having
member functions and operations for a
particular kind of data flow.
File  Program ( Input stream) - reads
Program  File (Output stream) – write
All designed into fstream.h and hence needs to
be included in all file handling programs.
A File can be stored in two ways
Text File
Binary File
Text Files : Stores information in ASCII characters. In text file
each line of text is terminated by with special character known
as EOL (End of Line) In text file some translations takes place
when this EOL character is read or written.
Binary File: it contains the information in the same format as
it is held in the memory. In binary file there is no delimiter for a
line. Also no translation occur in binary file. As a result binary
files are faster and easier for program to read and write.
Binary File Functions
Note: Both functions take two arguments.
• The first is the address of variable, and the second is the
length of that variable in bytes. The address of variable must
be type cast to type char*(pointer to character type)
• The data written to a file using write( ) can only be read
accurately using read( ).
Program to create a binary file ‘student.dat’ using structure.
#include<fstream.h>
struct student
{
char name[15];
float percent;
};
void main()
{
ofstream fout;
char ch;
fout.open(“student.dat”, ios::out | ios:: binary);
clrscr();
student s;
if(!fout)
{
cout<<“File can’t be opened”;
exit(0);
}
do
{ cout<<”n
enter name of student”;
gets(s.name);
cout<<”n enter percentage”;
cin>>s.percent;
fout.write((char *)&s,sizeof(s)); // writing a record in a student.dat file
cout<<”n more record y/n”;
cin>>ch;
}while(ch!=’n’ || ch!=’N’);
fout.close();
}
Deleting a Record from already existing file :
Algorithm :
 Assume the file already existed with the student structure.
(Each record contains percentage and name).
Declare a ifstream object and make it point to the existing
binary file student.dat and open it using input mode.
Ask the user to input the name of the student whose record
to be deleted. Store it in a String variable.
Declare a ofstream object and make it point to temporary
file (temp.dat) and open it in output mode.
Read each record from file and store it in a structure object.
(this can be achieved using read() ).
Compare the name of the record read into object and name
of record to be deleted .
CONTD…..
Deleting a Record from already existing file :
If both are not matching write the contents of the object into
the temporary file using write().
If both are matching skip the writing into the file.
Repeat the process till all the records are traversed
Close the connections associated with the both the objects
Delete the file (student.dat) using remove()
Rename the temporary file to the original file name.
Note : The process is same for text files also but the binary
modes are not needed. Read data line by line and compare
with target data to be deleted. Skip writing to temporary file if
both are matching.
Program to delete a record from a binary file
‘student.dat’
#include<fstream.h>
struct student
{
char name[15];
float percent;
};
void main()
{
ifstream fin;
student s;
char dname[15]; //to read the name of the record to delete
fin.open(“student.dat”,ios::in | ios:: binary);
ofstream fout(“temp.dat”,ios::out|ios::binary);
cout<<“n Enter name of the student whose record to be
deleted”;
cin>>dname;
while(fin.read((char *) &s, sizeof(student))
{
if(strcmp(s.name,dname)!=0)
fout.write((char *) &s, sizeof(s));
}
fin.close();
fout.close();
remove(“student.dat”);
rename(“temp.dat”,”student.dat”);
getch();
}
File Pointer
seekp(): It places the file pointer to the specified position in
output mode of file.
e.g file.seekp(p,ios::beg); or file.seekp(-p,ios::end), or
file.seekp(p,ios::cur)
i.e to move to p byte position from beginning, end or current
position.
tellg(): This function returns the current working position of the
file pointer in the input mode.
e.g int p=file.tellg();
tellp(): This function returns the current working position of the
file pointer in the output mode.
e.f int p=file.tellp();
Deletion of a Record from a File - K Karun
Deletion of a Record from a File - K Karun

More Related Content

What's hot (19)

CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 
Data file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing filesData file handling in python introduction,opening & closing files
Data file handling in python introduction,opening & closing files
 
Filehandlinging cp2
Filehandlinging cp2Filehandlinging cp2
Filehandlinging cp2
 
file management functions
file management functionsfile management functions
file management functions
 
Javaio
JavaioJavaio
Javaio
 
Reading and Writing Files
Reading and Writing FilesReading and Writing Files
Reading and Writing Files
 
File handling
File handlingFile handling
File handling
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
ASP.NET Session 7
ASP.NET Session 7ASP.NET Session 7
ASP.NET Session 7
 
data file handling
data file handlingdata file handling
data file handling
 
C files
C filesC files
C files
 
Streams and Files
Streams and FilesStreams and Files
Streams and Files
 
C# File IO Operations
C# File IO OperationsC# File IO Operations
C# File IO Operations
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Managing console of I/o operations & working with files
Managing console of I/o operations & working with filesManaging console of I/o operations & working with files
Managing console of I/o operations & working with files
 
Lecture 23
Lecture 23Lecture 23
Lecture 23
 
File handling
File handlingFile handling
File handling
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
File handling
File handlingFile handling
File handling
 

Viewers also liked

Indexing and-hashing
Indexing and-hashingIndexing and-hashing
Indexing and-hashingAmi Ranjit
 
Lecture.extendible.hashing
Lecture.extendible.hashingLecture.extendible.hashing
Lecture.extendible.hashingChace Liang
 
Drawback of Internet of Things - Battery Life
Drawback of Internet of Things - Battery LifeDrawback of Internet of Things - Battery Life
Drawback of Internet of Things - Battery LifeAdithya Jayaprakash
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operationsTAlha MAlik
 
Database intro
Database introDatabase intro
Database introKara Ross
 
Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Vidyasagar Mundroy
 
Database management system1
Database management system1Database management system1
Database management system1jamwal85
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-fileDeepak Singh
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagramMayank Jain
 
DBMS topics for BCA
DBMS topics for BCADBMS topics for BCA
DBMS topics for BCAAdbay
 
1 introduction databases and database users
1 introduction databases and database users1 introduction databases and database users
1 introduction databases and database usersKumar
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniquesahmadmughal0312
 
File organization techniques
File organization techniquesFile organization techniques
File organization techniquesMeghlal Khan
 

Viewers also liked (20)

Indexing and-hashing
Indexing and-hashingIndexing and-hashing
Indexing and-hashing
 
Normal forms
Normal formsNormal forms
Normal forms
 
Lecture.extendible.hashing
Lecture.extendible.hashingLecture.extendible.hashing
Lecture.extendible.hashing
 
Chapter13
Chapter13Chapter13
Chapter13
 
Drawback of Internet of Things - Battery Life
Drawback of Internet of Things - Battery LifeDrawback of Internet of Things - Battery Life
Drawback of Internet of Things - Battery Life
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operations
 
Database intro
Database introDatabase intro
Database intro
 
Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)Database Systems - Relational Data Model (Chapter 2)
Database Systems - Relational Data Model (Chapter 2)
 
Filehandling
FilehandlingFilehandling
Filehandling
 
Chapter2
Chapter2Chapter2
Chapter2
 
Database management system1
Database management system1Database management system1
Database management system1
 
Databse management system
Databse management systemDatabse management system
Databse management system
 
Chpater29 operation-on-file
Chpater29 operation-on-fileChpater29 operation-on-file
Chpater29 operation-on-file
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
DBMS topics for BCA
DBMS topics for BCADBMS topics for BCA
DBMS topics for BCA
 
Indexing Data Structure
Indexing Data StructureIndexing Data Structure
Indexing Data Structure
 
1 introduction databases and database users
1 introduction databases and database users1 introduction databases and database users
1 introduction databases and database users
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniques
 
File organization techniques
File organization techniquesFile organization techniques
File organization techniques
 

Similar to Deletion of a Record from a File - K Karun

chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfstudy material
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))Papu Kumar
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5YOGESH SINGH
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with exampleSunil Patel
 
Python reading and writing files
Python reading and writing filesPython reading and writing files
Python reading and writing filesMukesh Tekwani
 
File Handling in C Part I
File Handling in C Part IFile Handling in C Part I
File Handling in C Part IArpana Awasthi
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfsudhakargeruganti
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxAssadLeo1
 

Similar to Deletion of a Record from a File - K Karun (20)

7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
chapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdfchapter-12-data-file-handling.pdf
chapter-12-data-file-handling.pdf
 
Data file handling
Data file handlingData file handling
Data file handling
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
File management in C++
File management in C++File management in C++
File management in C++
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 
Basics of files and its functions with example
Basics of files and its functions with exampleBasics of files and its functions with example
Basics of files and its functions with example
 
Python reading and writing files
Python reading and writing filesPython reading and writing files
Python reading and writing files
 
File Handling in C Part I
File Handling in C Part IFile Handling in C Part I
File Handling in C Part I
 
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
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
File Organization
File OrganizationFile Organization
File Organization
 
IOStream.pptx
IOStream.pptxIOStream.pptx
IOStream.pptx
 
INput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptxINput output stream in ccP Full Detail.pptx
INput output stream in ccP Full Detail.pptx
 
file_c.pdf
file_c.pdffile_c.pdf
file_c.pdf
 

More from Dipayan Sarkar

introduction to aep arc
introduction to aep arcintroduction to aep arc
introduction to aep arcDipayan Sarkar
 
why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needsDipayan Sarkar
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forwardDipayan Sarkar
 
Softskills - S Fernandez
Softskills - S FernandezSoftskills - S Fernandez
Softskills - S FernandezDipayan Sarkar
 
Project Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaProject Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaDipayan Sarkar
 
Linux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarLinux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarDipayan Sarkar
 
File Handling - N K Upadhyay
File Handling - N K UpadhyayFile Handling - N K Upadhyay
File Handling - N K UpadhyayDipayan Sarkar
 
Sorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishSorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishDipayan Sarkar
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaDipayan Sarkar
 
Information Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakInformation Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakDipayan Sarkar
 
Universal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliUniversal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliDipayan Sarkar
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin RamolaDipayan Sarkar
 
Java Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseJava Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseDipayan Sarkar
 
Computer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyComputer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyDipayan Sarkar
 
Cloud Computing- Sreehari S
Cloud Computing- Sreehari SCloud Computing- Sreehari S
Cloud Computing- Sreehari SDipayan Sarkar
 

More from Dipayan Sarkar (18)

Relationships
RelationshipsRelationships
Relationships
 
ideal learning space
ideal learning spaceideal learning space
ideal learning space
 
introduction to aep arc
introduction to aep arcintroduction to aep arc
introduction to aep arc
 
why focus on adolescents unique needs
why focus on adolescents unique needswhy focus on adolescents unique needs
why focus on adolescents unique needs
 
aep in india milestones, learning, way forward
aep in india milestones, learning, way forwardaep in india milestones, learning, way forward
aep in india milestones, learning, way forward
 
Softskills - S Fernandez
Softskills - S FernandezSoftskills - S Fernandez
Softskills - S Fernandez
 
Project Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K ChaurdiaProject Based Learning- Ashish K Chaurdia
Project Based Learning- Ashish K Chaurdia
 
Linux and the Open Source- D Sarkar
Linux and the Open Source- D SarkarLinux and the Open Source- D Sarkar
Linux and the Open Source- D Sarkar
 
File Handling - N K Upadhyay
File Handling - N K UpadhyayFile Handling - N K Upadhyay
File Handling - N K Upadhyay
 
Sorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan SatishSorting Techniques - Govardhan Satish
Sorting Techniques - Govardhan Satish
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Information Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K PathakInformation Technology Act 2000 - Santosh K Pathak
Information Technology Act 2000 - Santosh K Pathak
 
Universal Gates - Aneesa N Ali
Universal Gates - Aneesa N AliUniversal Gates - Aneesa N Ali
Universal Gates - Aneesa N Ali
 
Selection Sort - Vipin Ramola
Selection Sort - Vipin RamolaSelection Sort - Vipin Ramola
Selection Sort - Vipin Ramola
 
Java Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex JoseJava Databse Connectvity- Alex Jose
Java Databse Connectvity- Alex Jose
 
Computer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan ChakravarthyComputer Viruses- B S Kalyan Chakravarthy
Computer Viruses- B S Kalyan Chakravarthy
 
Cloud Computing- Sreehari S
Cloud Computing- Sreehari SCloud Computing- Sreehari S
Cloud Computing- Sreehari S
 
SQL JOINS- Reena P V
SQL JOINS- Reena P VSQL JOINS- Reena P V
SQL JOINS- Reena P V
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

Deletion of a Record from a File - K Karun

  • 1. KURUVA KARUN PGT COMP SCIENCE KVNO.2 VASCO BANGALORE REGION
  • 2. Understanding the basic concept of file handling. Types of files. Functions associated to operate on binary files. Deleting a record from binary file. 2All rights reserved
  • 3.  Computer programs are associated to work with files as it helps in storing data & information permanently.  File - itself a bunch of bytes stored on some storage devices.  In C++ this is achieved through a component header file called fstream.h  The I/O library manages two aspects- as interface and for transfer of data.  The library predefine a set of operations for all file related handling through certain classes.
  • 4.  stream is a general term used to name flow of data. Streams act as an interface between files and programs. A Stream is sequence of bytes. They represent as a sequence of bytes and deals with the flow of data. Every stream is associated with a class having member functions and operations for a particular kind of data flow. File  Program ( Input stream) - reads Program  File (Output stream) – write All designed into fstream.h and hence needs to be included in all file handling programs.
  • 5.
  • 6. A File can be stored in two ways Text File Binary File Text Files : Stores information in ASCII characters. In text file each line of text is terminated by with special character known as EOL (End of Line) In text file some translations takes place when this EOL character is read or written. Binary File: it contains the information in the same format as it is held in the memory. In binary file there is no delimiter for a line. Also no translation occur in binary file. As a result binary files are faster and easier for program to read and write.
  • 7. Binary File Functions Note: Both functions take two arguments. • The first is the address of variable, and the second is the length of that variable in bytes. The address of variable must be type cast to type char*(pointer to character type) • The data written to a file using write( ) can only be read accurately using read( ).
  • 8. Program to create a binary file ‘student.dat’ using structure. #include<fstream.h> struct student { char name[15]; float percent; }; void main() { ofstream fout; char ch; fout.open(“student.dat”, ios::out | ios:: binary); clrscr(); student s; if(!fout) { cout<<“File can’t be opened”; exit(0); }
  • 9. do { cout<<”n enter name of student”; gets(s.name); cout<<”n enter percentage”; cin>>s.percent; fout.write((char *)&s,sizeof(s)); // writing a record in a student.dat file cout<<”n more record y/n”; cin>>ch; }while(ch!=’n’ || ch!=’N’); fout.close(); }
  • 10. Deleting a Record from already existing file : Algorithm :  Assume the file already existed with the student structure. (Each record contains percentage and name). Declare a ifstream object and make it point to the existing binary file student.dat and open it using input mode. Ask the user to input the name of the student whose record to be deleted. Store it in a String variable. Declare a ofstream object and make it point to temporary file (temp.dat) and open it in output mode. Read each record from file and store it in a structure object. (this can be achieved using read() ). Compare the name of the record read into object and name of record to be deleted . CONTD…..
  • 11. Deleting a Record from already existing file : If both are not matching write the contents of the object into the temporary file using write(). If both are matching skip the writing into the file. Repeat the process till all the records are traversed Close the connections associated with the both the objects Delete the file (student.dat) using remove() Rename the temporary file to the original file name. Note : The process is same for text files also but the binary modes are not needed. Read data line by line and compare with target data to be deleted. Skip writing to temporary file if both are matching.
  • 12. Program to delete a record from a binary file ‘student.dat’ #include<fstream.h> struct student { char name[15]; float percent; }; void main() { ifstream fin; student s; char dname[15]; //to read the name of the record to delete fin.open(“student.dat”,ios::in | ios:: binary); ofstream fout(“temp.dat”,ios::out|ios::binary); cout<<“n Enter name of the student whose record to be deleted”; cin>>dname;
  • 13. while(fin.read((char *) &s, sizeof(student)) { if(strcmp(s.name,dname)!=0) fout.write((char *) &s, sizeof(s)); } fin.close(); fout.close(); remove(“student.dat”); rename(“temp.dat”,”student.dat”); getch(); }
  • 14. File Pointer seekp(): It places the file pointer to the specified position in output mode of file. e.g file.seekp(p,ios::beg); or file.seekp(-p,ios::end), or file.seekp(p,ios::cur) i.e to move to p byte position from beginning, end or current position. tellg(): This function returns the current working position of the file pointer in the input mode. e.g int p=file.tellg(); tellp(): This function returns the current working position of the file pointer in the output mode. e.f int p=file.tellp();