SlideShare a Scribd company logo
1 of 13
Lecture 23Lecture 23
Version 1.0Version 1.0
More on Files (Part II)More on Files (Part II)
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
Records in FileRecords in File
 So far we have manipulated files only withSo far we have manipulated files only with
characters and strings.characters and strings.
 What if you want to deal with numbers?What if you want to deal with numbers?
 What if you want to deal withWhat if you want to deal with
numbers/strings/characters all together?numbers/strings/characters all together?
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
The ProcedureThe Procedure
 These are dissimilar data typesThese are dissimilar data types
 We will use structure to combine these dissimilarWe will use structure to combine these dissimilar
data types into a single data structuredata types into a single data structure
 We will use fprintf ( ) to write them into fileWe will use fprintf ( ) to write them into file
 We will use fscanf ( ) to read from fileWe will use fscanf ( ) to read from file
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
Text & Binary FilesText & Binary Files
 A text file contains only textual information likeA text file contains only textual information like
alphabets, digits and special symbolsalphabets, digits and special symbols
 In actuality the ASCII codes of these charactersIn actuality the ASCII codes of these characters
are stored in text filesare stored in text files
 a binary file is merely a collection of bytesa binary file is merely a collection of bytes
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
Example of handling binary filesExample of handling binary files
 Remember the copy-paste program?Remember the copy-paste program?
 In that case, we handled only .TXT filesIn that case, we handled only .TXT files
 So, now we will modify the same program soSo, now we will modify the same program so
that the program can handle binary files as well.that the program can handle binary files as well.
 Don’t worryDon’t worry , it is almost the same program, it is almost the same program
as that one!as that one!
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
 The record I/O program that we did in anThe record I/O program that we did in an
earlier section has two disadvantages:earlier section has two disadvantages:
 The numbers (basic salary) would occupy moreThe numbers (basic salary) would occupy more
number of bytes- when the file is opened in textnumber of bytes- when the file is opened in text
mode, each number is stored as a charactermode, each number is stored as a character
string.string.
 If the number of fields in the structure increaseIf the number of fields in the structure increase
writing structures usingwriting structures using fprintf( )fprintf( ), or reading, or reading
them usingthem using fscanf( ),fscanf( ), becomes quite clumsy.becomes quite clumsy.
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
Efficient way to read/write recordsEfficient way to read/write records
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
fwrite ( &e, sizeof ( e ), 1, fp ) ;fwrite ( &e, sizeof ( e ), 1, fp ) ;
 first argument is the address of the structure tofirst argument is the address of the structure to
be written to the diskbe written to the disk
 second argument is the size of the structure insecond argument is the size of the structure in
bytesbytes
 third argument is the number of such structuresthird argument is the number of such structures
that we want to write at one timethat we want to write at one time
 argument is the pointer to the file we want toargument is the pointer to the file we want to
write towrite to
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
13Rushdi Shams, Dept of CSE, KUET, Bangladesh
fread ( )fread ( )
 If we have reached the end of file, sinceIf we have reached the end of file, since fread( )fread( )
cannot read anything, it returns a 0. By testingcannot read anything, it returns a 0. By testing
for this situation, we know when to stopfor this situation, we know when to stop
reading.reading.

More Related Content

Viewers also liked

Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesRushdi Shams
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and ArraysRushdi Shams
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMSRushdi Shams
 
L4 domain integrity
L4  domain integrityL4  domain integrity
L4 domain integrityRushdi Shams
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 

Viewers also liked (8)

Lec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by ValuesLec 09. Introduction to Functions / Call by Values
Lec 09. Introduction to Functions / Call by Values
 
Lec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory ConceptLec 02. C Program Structure / C Memory Concept
Lec 02. C Program Structure / C Memory Concept
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
Lec 15. Pointers and Arrays
Lec 15. Pointers and ArraysLec 15. Pointers and Arrays
Lec 15. Pointers and Arrays
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L14 l15 Object Oriented DBMS
L14 l15  Object Oriented DBMSL14 l15  Object Oriented DBMS
L14 l15 Object Oriented DBMS
 
L4 domain integrity
L4  domain integrityL4  domain integrity
L4 domain integrity
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 

Similar to Lec 23. Files (Part II)

File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugevsol7206
 
An Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired FileAn Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired FileIDES Editor
 
Comparison Study of Lossless Data Compression Algorithms for Text Data
Comparison Study of Lossless Data Compression Algorithms for Text DataComparison Study of Lossless Data Compression Algorithms for Text Data
Comparison Study of Lossless Data Compression Algorithms for Text DataIOSR Journals
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data TypesRushdi Shams
 
Python-File handling-slides-pkt
Python-File handling-slides-pktPython-File handling-slides-pkt
Python-File handling-slides-pktPradyumna Tripathy
 
Topic Mining on disaster data (Robert Monné)
Topic Mining on disaster data (Robert Monné)Topic Mining on disaster data (Robert Monné)
Topic Mining on disaster data (Robert Monné)Robert Monné
 
Automatic document clustering
Automatic document clusteringAutomatic document clustering
Automatic document clusteringIAEME Publication
 
Fota Delta Size Reduction Using FIle Similarity Algorithms
Fota Delta Size Reduction Using FIle Similarity AlgorithmsFota Delta Size Reduction Using FIle Similarity Algorithms
Fota Delta Size Reduction Using FIle Similarity AlgorithmsShivansh Gaur
 
Lpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationLpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationYemenLinux
 
Named entity recognition (ner) with nltk
Named entity recognition (ner) with nltkNamed entity recognition (ner) with nltk
Named entity recognition (ner) with nltkJanu Jahnavi
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++Vineeta Garg
 
A research paper_on_lossless_data_compre
A research paper_on_lossless_data_compreA research paper_on_lossless_data_compre
A research paper_on_lossless_data_compreLuisa Francisco
 
File System Comparison on Linux Ubuntu
File System Comparison on Linux UbuntuFile System Comparison on Linux Ubuntu
File System Comparison on Linux UbuntuJayesh Tambe
 

Similar to Lec 23. Files (Part II) (20)

File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
An Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired FileAn Efficient Search Engine for Searching Desired File
An Efficient Search Engine for Searching Desired File
 
Submission_36
Submission_36Submission_36
Submission_36
 
Comparison Study of Lossless Data Compression Algorithms for Text Data
Comparison Study of Lossless Data Compression Algorithms for Text DataComparison Study of Lossless Data Compression Algorithms for Text Data
Comparison Study of Lossless Data Compression Algorithms for Text Data
 
Lec 08. C Data Types
Lec 08. C Data TypesLec 08. C Data Types
Lec 08. C Data Types
 
Python-File handling-slides-pkt
Python-File handling-slides-pktPython-File handling-slides-pkt
Python-File handling-slides-pkt
 
Topic Mining on disaster data (Robert Monné)
Topic Mining on disaster data (Robert Monné)Topic Mining on disaster data (Robert Monné)
Topic Mining on disaster data (Robert Monné)
 
PYTHON PPT.pptx
PYTHON PPT.pptxPYTHON PPT.pptx
PYTHON PPT.pptx
 
Automatic document clustering
Automatic document clusteringAutomatic document clustering
Automatic document clustering
 
Files
FilesFiles
Files
 
Fota Delta Size Reduction Using FIle Similarity Algorithms
Fota Delta Size Reduction Using FIle Similarity AlgorithmsFota Delta Size Reduction Using FIle Similarity Algorithms
Fota Delta Size Reduction Using FIle Similarity Algorithms
 
Lpi Part 2 Basic Administration
Lpi Part 2 Basic AdministrationLpi Part 2 Basic Administration
Lpi Part 2 Basic Administration
 
Named entity recognition (ner) with nltk
Named entity recognition (ner) with nltkNamed entity recognition (ner) with nltk
Named entity recognition (ner) with nltk
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
1
11
1
 
A research paper_on_lossless_data_compre
A research paper_on_lossless_data_compreA research paper_on_lossless_data_compre
A research paper_on_lossless_data_compre
 
File System Comparison on Linux Ubuntu
File System Comparison on Linux UbuntuFile System Comparison on Linux Ubuntu
File System Comparison on Linux Ubuntu
 
Ijetcas14 444
Ijetcas14 444Ijetcas14 444
Ijetcas14 444
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process modelsRushdi Shams
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineeringRushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 
L2 l3 l4 software process models
L2 l3 l4  software process modelsL2 l3 l4  software process models
L2 l3 l4 software process models
 
L1 overview of software engineering
L1  overview of software engineeringL1  overview of software engineering
L1 overview of software engineering
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“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
 
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
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
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
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“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...
 
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 ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.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 🔝✔️✔️
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
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
 

Lec 23. Files (Part II)

  • 1. Lecture 23Lecture 23 Version 1.0Version 1.0 More on Files (Part II)More on Files (Part II)
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh Records in FileRecords in File  So far we have manipulated files only withSo far we have manipulated files only with characters and strings.characters and strings.  What if you want to deal with numbers?What if you want to deal with numbers?  What if you want to deal withWhat if you want to deal with numbers/strings/characters all together?numbers/strings/characters all together?
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh The ProcedureThe Procedure  These are dissimilar data typesThese are dissimilar data types  We will use structure to combine these dissimilarWe will use structure to combine these dissimilar data types into a single data structuredata types into a single data structure  We will use fprintf ( ) to write them into fileWe will use fprintf ( ) to write them into file  We will use fscanf ( ) to read from fileWe will use fscanf ( ) to read from file
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh Text & Binary FilesText & Binary Files  A text file contains only textual information likeA text file contains only textual information like alphabets, digits and special symbolsalphabets, digits and special symbols  In actuality the ASCII codes of these charactersIn actuality the ASCII codes of these characters are stored in text filesare stored in text files  a binary file is merely a collection of bytesa binary file is merely a collection of bytes
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh Example of handling binary filesExample of handling binary files  Remember the copy-paste program?Remember the copy-paste program?  In that case, we handled only .TXT filesIn that case, we handled only .TXT files  So, now we will modify the same program soSo, now we will modify the same program so that the program can handle binary files as well.that the program can handle binary files as well.  Don’t worryDon’t worry , it is almost the same program, it is almost the same program as that one!as that one!
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh  The record I/O program that we did in anThe record I/O program that we did in an earlier section has two disadvantages:earlier section has two disadvantages:  The numbers (basic salary) would occupy moreThe numbers (basic salary) would occupy more number of bytes- when the file is opened in textnumber of bytes- when the file is opened in text mode, each number is stored as a charactermode, each number is stored as a character string.string.  If the number of fields in the structure increaseIf the number of fields in the structure increase writing structures usingwriting structures using fprintf( )fprintf( ), or reading, or reading them usingthem using fscanf( ),fscanf( ), becomes quite clumsy.becomes quite clumsy.
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh Efficient way to read/write recordsEfficient way to read/write records
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh fwrite ( &e, sizeof ( e ), 1, fp ) ;fwrite ( &e, sizeof ( e ), 1, fp ) ;  first argument is the address of the structure tofirst argument is the address of the structure to be written to the diskbe written to the disk  second argument is the size of the structure insecond argument is the size of the structure in bytesbytes  third argument is the number of such structuresthird argument is the number of such structures that we want to write at one timethat we want to write at one time  argument is the pointer to the file we want toargument is the pointer to the file we want to write towrite to
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh fread ( )fread ( )  If we have reached the end of file, sinceIf we have reached the end of file, since fread( )fread( ) cannot read anything, it returns a 0. By testingcannot read anything, it returns a 0. By testing for this situation, we know when to stopfor this situation, we know when to stop reading.reading.