SlideShare une entreprise Scribd logo
1  sur  13
Lecture 22Lecture 22
Version 1.0Version 1.0
More on FilesMore on Files
2Rushdi Shams, Dept of CSE, KUET, Bangladesh
A File Copy ProgramA File Copy Program
 We will take a look at how you read from a fileWe will take a look at how you read from a file
 And then how you can put the content of thatAnd then how you can put the content of that
file into another filefile into another file
3Rushdi Shams, Dept of CSE, KUET, Bangladesh
4Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Read (r)Read (r)
Searches the fileSearches the file
If the search is successfulIf the search is successful
load the file into memoryload the file into memory
set a pointer at the beginning of the fileset a pointer at the beginning of the file
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Only reads from fileOnly reads from file
5Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Write (w)Write (w)
Searches the fileSearches the file
If the file existsIf the file exists
it is overwrittenit is overwritten
If notIf not
a new file is createda new file is created
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Only writes to fileOnly writes to file
6Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Append (a)Append (a)
Searches the fileSearches the file
If the search is successfulIf the search is successful
load the file into memoryload the file into memory
set a pointer at the end of the fileset a pointer at the end of the file
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Adding new contents in the fileAdding new contents in the file
7Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Append Plus (a+)Append Plus (a+)
Searches the fileSearches the file
If the search is successfulIf the search is successful
load the file into memoryload the file into memory
If not foundIf not found
create a new filecreate a new file
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Reading, appending in fileReading, appending in file
Cannot modifyCannot modify
8Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Read Plus (r+)Read Plus (r+)
Searches the fileSearches the file
If the search is successfulIf the search is successful
load the file into memoryload the file into memory
set a pointer at first characterset a pointer at first character
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Reading, writing, modifying contents in the fileReading, writing, modifying contents in the file
9Rushdi Shams, Dept of CSE, KUET, Bangladesh
File Opening ModesFile Opening Modes
 Write Plus (w+)Write Plus (w+)
Searches the fileSearches the file
If the file existsIf the file exists
it is overwrittenit is overwritten
If notIf not
a new file is createda new file is created
If the file cannot be openedIf the file cannot be opened
returns NULLreturns NULL
Writing, reading and modifying contentsWriting, reading and modifying contents
10Rushdi Shams, Dept of CSE, KUET, Bangladesh
String in FilesString in Files
 So far we have seen how to manipulateSo far we have seen how to manipulate
characters in filescharacters in files
 Now, we will see that handling strings in files isNow, we will see that handling strings in files is
as easy as handling charactersas easy as handling characters
 At first we will see how to write strings into aAt first we will see how to write strings into a
filefile
11Rushdi Shams, Dept of CSE, KUET, Bangladesh
12Rushdi Shams, Dept of CSE, KUET, Bangladesh
 Now we will see how to read strings from filesNow we will see how to read strings from files
13Rushdi Shams, Dept of CSE, KUET, Bangladesh

Contenu connexe

Similaire à File Copy Program Lecture - Read, Write Strings Files

File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugevsol7206
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15Vishal Dutt
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdfsulekha24
 
Python Files I_O17.pdf
Python Files I_O17.pdfPython Files I_O17.pdf
Python Files I_O17.pdfRashmiAngane1
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
File handing in C
File handing in CFile handing in C
File handing in Cshrishcg
 
File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in pythonnitamhaske
 
what are python basics.pptx.Join Python training in Chandigarh
what are python basics.pptx.Join Python training in Chandigarhwhat are python basics.pptx.Join Python training in Chandigarh
what are python basics.pptx.Join Python training in Chandigarhasmeerana605
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxarmaansohail9356
 

Similaire à File Copy Program Lecture - Read, Write Strings Files (20)

File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reugeFile handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
File handling3 (1).pdf uhgipughserigrfiogrehpiuhnfi;reuge
 
pspp-rsk.pptx
pspp-rsk.pptxpspp-rsk.pptx
pspp-rsk.pptx
 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
Python files / directories part15
Python files / directories  part15Python files / directories  part15
Python files / directories part15
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdf
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 
Python Files I_O17.pdf
Python Files I_O17.pdfPython Files I_O17.pdf
Python Files I_O17.pdf
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
File Handling in C
File Handling in CFile Handling in C
File Handling in C
 
File accessing modes in c
File accessing modes in cFile accessing modes in c
File accessing modes in c
 
File handling3.pdf
File handling3.pdfFile handling3.pdf
File handling3.pdf
 
File handling in c
File handling in cFile handling in c
File handling in c
 
File handling
File handlingFile handling
File handling
 
File handing in C
File handing in CFile handing in C
File handing in C
 
File handling and Dictionaries in python
File handling and Dictionaries in pythonFile handling and Dictionaries in python
File handling and Dictionaries in python
 
what are python basics.pptx.Join Python training in Chandigarh
what are python basics.pptx.Join Python training in Chandigarhwhat are python basics.pptx.Join Python training in Chandigarh
what are python basics.pptx.Join Python training in Chandigarh
 
Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
 
Com ed 5 final
Com ed 5 finalCom ed 5 final
Com ed 5 final
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
 

Plus de 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
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic 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
 

Plus de 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
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic 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
 
L3 defense
L3  defenseL3  defense
L3 defense
 
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
 

Dernier

Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 

Dernier (20)

FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 

File Copy Program Lecture - Read, Write Strings Files

  • 1. Lecture 22Lecture 22 Version 1.0Version 1.0 More on FilesMore on Files
  • 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh A File Copy ProgramA File Copy Program  We will take a look at how you read from a fileWe will take a look at how you read from a file  And then how you can put the content of thatAnd then how you can put the content of that file into another filefile into another file
  • 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Read (r)Read (r) Searches the fileSearches the file If the search is successfulIf the search is successful load the file into memoryload the file into memory set a pointer at the beginning of the fileset a pointer at the beginning of the file If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Only reads from fileOnly reads from file
  • 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Write (w)Write (w) Searches the fileSearches the file If the file existsIf the file exists it is overwrittenit is overwritten If notIf not a new file is createda new file is created If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Only writes to fileOnly writes to file
  • 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Append (a)Append (a) Searches the fileSearches the file If the search is successfulIf the search is successful load the file into memoryload the file into memory set a pointer at the end of the fileset a pointer at the end of the file If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Adding new contents in the fileAdding new contents in the file
  • 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Append Plus (a+)Append Plus (a+) Searches the fileSearches the file If the search is successfulIf the search is successful load the file into memoryload the file into memory If not foundIf not found create a new filecreate a new file If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Reading, appending in fileReading, appending in file Cannot modifyCannot modify
  • 8. 8Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Read Plus (r+)Read Plus (r+) Searches the fileSearches the file If the search is successfulIf the search is successful load the file into memoryload the file into memory set a pointer at first characterset a pointer at first character If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Reading, writing, modifying contents in the fileReading, writing, modifying contents in the file
  • 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh File Opening ModesFile Opening Modes  Write Plus (w+)Write Plus (w+) Searches the fileSearches the file If the file existsIf the file exists it is overwrittenit is overwritten If notIf not a new file is createda new file is created If the file cannot be openedIf the file cannot be opened returns NULLreturns NULL Writing, reading and modifying contentsWriting, reading and modifying contents
  • 10. 10Rushdi Shams, Dept of CSE, KUET, Bangladesh String in FilesString in Files  So far we have seen how to manipulateSo far we have seen how to manipulate characters in filescharacters in files  Now, we will see that handling strings in files isNow, we will see that handling strings in files is as easy as handling charactersas easy as handling characters  At first we will see how to write strings into aAt first we will see how to write strings into a filefile
  • 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh
  • 12. 12Rushdi Shams, Dept of CSE, KUET, Bangladesh  Now we will see how to read strings from filesNow we will see how to read strings from files
  • 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh