SlideShare a Scribd company logo
1 of 22
Download to read offline
Prog_2 course- 2014 
2 bytes team 
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year
Files 
TxT Files 
char(ACII) 
Binary File 
0/1
Who can tell me from where we read and write in our normal program? 
In Files: Keyboard file Screen file 
Why files? To save things..(whereas in normal way we cant save things after program end).. Then we can read|| write from it ! 
NOTE: First of all.. We have to know that each file has Pointer at the Begin of file and Pointer at the End of it -The end of line determined by (Enter) #13
There is : 
Physical name ( koko.txt /koko.bin) 
logical name (f:txt / f:file of _sth_) 
File : 
read 
write 
Note: Attention !! The most important thing is the method we read and write files 
modification 
has its arrangement(use another file to help )
TXT FILES
The Definition 
At main Program: 
Var f :Text; 
At procedures/functions: 
procedure ___(…Var f :txt) 
We use “Assign” to link physical name with logical name: Assign(f,<filename>) 
-If the file at (Bin)(the same folder of pascal) : you don‟t have to write whole direction Ex:(Assign(f,‟soso.txt‟) ) -else you have to write whole direction Ex:(Assign(f ,‟D:fififofo….soso.txt‟) )
The Definition 
At main Program: 
Var f :TXT; 
At procedures/functions: 
procedure ___(…Var f :txt) 
We use “Assign” to link physical name with logical name: Assign(f,<filename>) 
-If the file at (Bin)(the same folder of pascal) : you don‟t have to write whole direction Ex:(Assign(f,‟soso.txt‟) ) -else you have to write whole direction Ex:(Assign(f ,‟D:fififofo….soso.txt‟) )
Read from Txtfile 
Reset(f) 
Read(f,c); (when you dunno how the file is created ) 
Readln(f,st); 
Readln(f); 
+1 
close(f)
write from Txtfile 
Rewrite(f) 
write(f,c); 
writeln(f,st); 
writeln(f); 
+1 
close(f)
Notes On Reset/Rewrite: 
If File exist 
If File Not exist 
Reset 
Put the Pointer at the begin of file .. 
Error 
Rewrite 
Erase file content 
And put the Pointer at the begin of file to write 
Create new file
How can we know the end of file ?? How can we do the end of line ? 
Eof(f): return true when the file end. 
Eoln (f): return true when the line end.
Lets make it real :D !!
-------- 
EMPno EMPName SAL 
100 saeed 5000 
2 Eyad 25000 
78 
-------- 
------------ 
. 
. 
. 
. 
. 
Ques: We want to write a Txt file like that below ..and read from it and print its content on Screen :
Write on file: 
Program Soso; 
Var filename:string[20]; 
f:txt; i:integer; c:char; st:string[100]; 
Eno:integer; Ename:string[40]; Esal:real; 
Begin 
readln(filename); Assign(f, filename); 
Rewrite(f); 
writeln(f, „EMPno‟:15,‟EMPName‟:15,‟ SAL‟:20); 
writeln(f,‟----------‟,‟ -----------------‟,‟-----------‟); 
for i:=1 to 100 do 
begin 
readln(Eno,Ename,Esal); 
writeln(f,Eno,Ename,Esal); 
end; 
close(f); 
End.
Read form file 
1) (because)/if we know the structure /how it is written : 
Reset(f); 
Readln(f,st); Readln(f,st); 
While not eof(f) do 
Begin 
readln(f, Eno,Ename,Esal); 
writeln(Eno,Ename,Esal); 
end; 
Close(f); 
+1
2) (because)/if we don’t know the structure /how it is written : 
Reset(f); 
While not eof(f) do 
Begin 
while not eoln(f) do 
begin 
read(f, c); 
write(c); 
end; 
writeln; readln(f); 
end; 
Close(f); 
Reset(f); 
While not eof(f) do 
Begin 
while not eoln(f) do 
begin 
readln(f, st); 
writeln(st); 
end; 
end; 
Close(f); 
Line long 
You have to define the big number string
Important Example 
PC Computer 
We have Txtfile In English( of course :p ) 
-Each word ends at its line. 
-Between words there is Only one Space „ ‟. 
There are in this file words “Computer” .. We want replace them by ”PC”.. 
You have to Keep your eyes with me all..
Program ComputerToPC; 
VAR 
f, new: text; 
ch: Char; 
s: string[8]; 
i: integer; 
flag: boolean; 
Begin 
assign(f,'mo.txt'); 
reset(f); 
assign(new,'new.txt'); 
rewrite(new);
while not eof(f) do 
begin 
flag := true; 
while not eoln(f) do 
begin 
if flag then 
read(f, s) 
else 
begin 
read(f, ch); 
s[8] := ch; 
end; 
if s = 'computer' then 
begin 
write(new, 'PC'); 
flag := true; 
end 
else 
begin 
flag := false; 
if eoln(f) then 
write(new, s) 
else 
write(new, s[1]); 
for i := 1 to 7 do 
s[i] := s[i+1]; 
end; 
end; 
readln(f); 
writeln(new); 
end; 
close(new); 
readln; 
End.{program}
When we want to open an existing text file for writing at the end of it , without removing its original contents using the procedure Append 
Appending to a text file: 
Program Soso; 
Var filename:string[20]; 
f:txt; st:string[10]; 
Begin 
readln(filename); Assign(f, filename); 
Append(f); 
writeln(„put what do you want at the End of file : ‟); 
readln(st); 
writeln(f,st); 
close(f); 
End.
Homework: you have a TXTfile it contains Student name/student number/prog_1 mark/prog_2 mark/ 1)put the sum of the two subjects to this file , then ensure of that. 2)print the sum of the two subjects on screen 
+10 points 
+7 
+3
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team

More Related Content

What's hot

File Management in C
File Management in CFile Management in C
File Management in CPaurav Shah
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'Gaurav Garg
 
File handling in c
File handling in c File handling in c
File handling in c Vikash Dhal
 
file handling1
file handling1file handling1
file handling1student
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersDavide Ciambelli
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-duttAnil Dutt
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsingFelix Z. Hoffmann
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list nisivaasdfghj
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Noé Fernández-Pozo
 
Python 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetPython 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetIsham Rashik
 
Concept of file handling in c
Concept of file handling in cConcept of file handling in c
Concept of file handling in cMugdhaSharma11
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10patcha535
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHPNicole Ryan
 

What's hot (19)

File Management in C
File Management in CFile Management in C
File Management in C
 
Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
 
File handling in 'C'
File handling in 'C'File handling in 'C'
File handling in 'C'
 
File handling in c
File handling in c File handling in c
File handling in c
 
file handling1
file handling1file handling1
file handling1
 
File handling in c
File  handling in cFile  handling in c
File handling in c
 
File Management
File ManagementFile Management
File Management
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 
File handling-dutt
File handling-duttFile handling-dutt
File handling-dutt
 
File management
File managementFile management
File management
 
Linux cheat-sheet
Linux cheat-sheetLinux cheat-sheet
Linux cheat-sheet
 
Python - File operations & Data parsing
Python - File operations & Data parsingPython - File operations & Data parsing
Python - File operations & Data parsing
 
1file handling
1file handling1file handling
1file handling
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
 
Python 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation CheatsheetPython 3.x File Object Manipulation Cheatsheet
Python 3.x File Object Manipulation Cheatsheet
 
Concept of file handling in c
Concept of file handling in cConcept of file handling in c
Concept of file handling in c
 
Chapter 13.1.10
Chapter 13.1.10Chapter 13.1.10
Chapter 13.1.10
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
 

Viewers also liked

I закон ньютона
I  закон ньютонаI  закон ньютона
I закон ньютонаLora Kravchenko
 
Threads Magazine "Denim Challenge" finalists
Threads Magazine "Denim Challenge" finalistsThreads Magazine "Denim Challenge" finalists
Threads Magazine "Denim Challenge" finalistsJennifer Hopkins Sherrill
 
Consumo saludable de bebidas en los niños
Consumo  saludable de bebidas en los niñosConsumo  saludable de bebidas en los niños
Consumo saludable de bebidas en los niñosMarian-vale1980
 
памятка
памяткапамятка
памяткаtoledos
 
Herramientas del taller
Herramientas del tallerHerramientas del taller
Herramientas del tallerevarp17
 
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)Vanessa Regueiro
 
Ray poynter social media research - 2012 - 2
Ray poynter   social media research - 2012 - 2Ray poynter   social media research - 2012 - 2
Ray poynter social media research - 2012 - 2Ray Poynter
 
Presion mapa conceptual
Presion mapa conceptualPresion mapa conceptual
Presion mapa conceptualAna Benavente
 
Från strategi till handlingsplan 120322
Från strategi till handlingsplan 120322Från strategi till handlingsplan 120322
Från strategi till handlingsplan 120322Johanna Karlén
 
Pasabahce linked in
Pasabahce linked inPasabahce linked in
Pasabahce linked inpasabahce
 
What Is A HVAC Load Calculation And Why Is It Important?
What Is A HVAC Load Calculation And Why Is It Important?What Is A HVAC Load Calculation And Why Is It Important?
What Is A HVAC Load Calculation And Why Is It Important?Hays Cooling,Heating & Plumbing
 

Viewers also liked (17)

I закон ньютона
I  закон ньютонаI  закон ньютона
I закон ньютона
 
Threads Magazine "Denim Challenge" finalists
Threads Magazine "Denim Challenge" finalistsThreads Magazine "Denim Challenge" finalists
Threads Magazine "Denim Challenge" finalists
 
Consumo saludable de bebidas en los niños
Consumo  saludable de bebidas en los niñosConsumo  saludable de bebidas en los niños
Consumo saludable de bebidas en los niños
 
Historia telmex
Historia telmexHistoria telmex
Historia telmex
 
BEST TRAVEL ARMENIA
BEST TRAVEL ARMENIABEST TRAVEL ARMENIA
BEST TRAVEL ARMENIA
 
портфолио начало33
портфолио начало33портфолио начало33
портфолио начало33
 
памятка
памяткапамятка
памятка
 
Tablet ppt
Tablet pptTablet ppt
Tablet ppt
 
How to Maintain & Clean your Dishwasher
How to Maintain & Clean your DishwasherHow to Maintain & Clean your Dishwasher
How to Maintain & Clean your Dishwasher
 
Presentacion personal
Presentacion personalPresentacion personal
Presentacion personal
 
Herramientas del taller
Herramientas del tallerHerramientas del taller
Herramientas del taller
 
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)
DEFECTOS DE LA ESTRUCTURA CRISTALINA (VANESSA REGUEIRO)
 
Ray poynter social media research - 2012 - 2
Ray poynter   social media research - 2012 - 2Ray poynter   social media research - 2012 - 2
Ray poynter social media research - 2012 - 2
 
Presion mapa conceptual
Presion mapa conceptualPresion mapa conceptual
Presion mapa conceptual
 
Från strategi till handlingsplan 120322
Från strategi till handlingsplan 120322Från strategi till handlingsplan 120322
Från strategi till handlingsplan 120322
 
Pasabahce linked in
Pasabahce linked inPasabahce linked in
Pasabahce linked in
 
What Is A HVAC Load Calculation And Why Is It Important?
What Is A HVAC Load Calculation And Why Is It Important?What Is A HVAC Load Calculation And Why Is It Important?
What Is A HVAC Load Calculation And Why Is It Important?
 

Similar to 2Bytesprog2 course_2014_c3_txtfiles

Similar to 2Bytesprog2 course_2014_c3_txtfiles (20)

File Handling in c.ppt
File Handling in c.pptFile Handling in c.ppt
File Handling in c.ppt
 
File handling-c
File handling-cFile handling-c
File handling-c
 
file_handling_in_c.ppt
file_handling_in_c.pptfile_handling_in_c.ppt
file_handling_in_c.ppt
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
PPS PPT 2.pptx
PPS PPT 2.pptxPPS PPT 2.pptx
PPS PPT 2.pptx
 
Satz1
Satz1Satz1
Satz1
 
Unit5
Unit5Unit5
Unit5
 
4 text file
4 text file4 text file
4 text file
 
FILE HANDLING.pptx
FILE HANDLING.pptxFILE HANDLING.pptx
FILE HANDLING.pptx
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Unit-VI.pptx
Unit-VI.pptxUnit-VI.pptx
Unit-VI.pptx
 
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
 
Files_in_C.ppt
Files_in_C.pptFiles_in_C.ppt
Files_in_C.ppt
 
C Programming Unit-5
C Programming Unit-5C Programming Unit-5
C Programming Unit-5
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdf
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
FILES IN C
FILES IN CFILES IN C
FILES IN C
 

More from kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_listskinan keshkeh
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked listkinan keshkeh
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointerskinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfileskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templateskinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritancekinan keshkeh
 

More from kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c7_double_lists
 
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c6_single linked list
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance
 

Recently uploaded

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 

Recently uploaded (20)

The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

2Bytesprog2 course_2014_c3_txtfiles

  • 1. Prog_2 course- 2014 2 bytes team Kinan keshkeh IT Engineering-Damascus University 3rd year
  • 2. Files TxT Files char(ACII) Binary File 0/1
  • 3. Who can tell me from where we read and write in our normal program? In Files: Keyboard file Screen file Why files? To save things..(whereas in normal way we cant save things after program end).. Then we can read|| write from it ! NOTE: First of all.. We have to know that each file has Pointer at the Begin of file and Pointer at the End of it -The end of line determined by (Enter) #13
  • 4. There is : Physical name ( koko.txt /koko.bin) logical name (f:txt / f:file of _sth_) File : read write Note: Attention !! The most important thing is the method we read and write files modification has its arrangement(use another file to help )
  • 6. The Definition At main Program: Var f :Text; At procedures/functions: procedure ___(…Var f :txt) We use “Assign” to link physical name with logical name: Assign(f,<filename>) -If the file at (Bin)(the same folder of pascal) : you don‟t have to write whole direction Ex:(Assign(f,‟soso.txt‟) ) -else you have to write whole direction Ex:(Assign(f ,‟D:fififofo….soso.txt‟) )
  • 7. The Definition At main Program: Var f :TXT; At procedures/functions: procedure ___(…Var f :txt) We use “Assign” to link physical name with logical name: Assign(f,<filename>) -If the file at (Bin)(the same folder of pascal) : you don‟t have to write whole direction Ex:(Assign(f,‟soso.txt‟) ) -else you have to write whole direction Ex:(Assign(f ,‟D:fififofo….soso.txt‟) )
  • 8. Read from Txtfile Reset(f) Read(f,c); (when you dunno how the file is created ) Readln(f,st); Readln(f); +1 close(f)
  • 9. write from Txtfile Rewrite(f) write(f,c); writeln(f,st); writeln(f); +1 close(f)
  • 10. Notes On Reset/Rewrite: If File exist If File Not exist Reset Put the Pointer at the begin of file .. Error Rewrite Erase file content And put the Pointer at the begin of file to write Create new file
  • 11. How can we know the end of file ?? How can we do the end of line ? Eof(f): return true when the file end. Eoln (f): return true when the line end.
  • 12. Lets make it real :D !!
  • 13. -------- EMPno EMPName SAL 100 saeed 5000 2 Eyad 25000 78 -------- ------------ . . . . . Ques: We want to write a Txt file like that below ..and read from it and print its content on Screen :
  • 14. Write on file: Program Soso; Var filename:string[20]; f:txt; i:integer; c:char; st:string[100]; Eno:integer; Ename:string[40]; Esal:real; Begin readln(filename); Assign(f, filename); Rewrite(f); writeln(f, „EMPno‟:15,‟EMPName‟:15,‟ SAL‟:20); writeln(f,‟----------‟,‟ -----------------‟,‟-----------‟); for i:=1 to 100 do begin readln(Eno,Ename,Esal); writeln(f,Eno,Ename,Esal); end; close(f); End.
  • 15. Read form file 1) (because)/if we know the structure /how it is written : Reset(f); Readln(f,st); Readln(f,st); While not eof(f) do Begin readln(f, Eno,Ename,Esal); writeln(Eno,Ename,Esal); end; Close(f); +1
  • 16. 2) (because)/if we don’t know the structure /how it is written : Reset(f); While not eof(f) do Begin while not eoln(f) do begin read(f, c); write(c); end; writeln; readln(f); end; Close(f); Reset(f); While not eof(f) do Begin while not eoln(f) do begin readln(f, st); writeln(st); end; end; Close(f); Line long You have to define the big number string
  • 17. Important Example PC Computer We have Txtfile In English( of course :p ) -Each word ends at its line. -Between words there is Only one Space „ ‟. There are in this file words “Computer” .. We want replace them by ”PC”.. You have to Keep your eyes with me all..
  • 18. Program ComputerToPC; VAR f, new: text; ch: Char; s: string[8]; i: integer; flag: boolean; Begin assign(f,'mo.txt'); reset(f); assign(new,'new.txt'); rewrite(new);
  • 19. while not eof(f) do begin flag := true; while not eoln(f) do begin if flag then read(f, s) else begin read(f, ch); s[8] := ch; end; if s = 'computer' then begin write(new, 'PC'); flag := true; end else begin flag := false; if eoln(f) then write(new, s) else write(new, s[1]); for i := 1 to 7 do s[i] := s[i+1]; end; end; readln(f); writeln(new); end; close(new); readln; End.{program}
  • 20. When we want to open an existing text file for writing at the end of it , without removing its original contents using the procedure Append Appending to a text file: Program Soso; Var filename:string[20]; f:txt; st:string[10]; Begin readln(filename); Assign(f, filename); Append(f); writeln(„put what do you want at the End of file : ‟); readln(st); writeln(f,st); close(f); End.
  • 21. Homework: you have a TXTfile it contains Student name/student number/prog_1 mark/prog_2 mark/ 1)put the sum of the two subjects to this file , then ensure of that. 2)print the sum of the two subjects on screen +10 points +7 +3
  • 22. Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team