SlideShare a Scribd company logo
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

PPT
File handling
PPTX
File handling in c
PPTX
File in C language
PPT
File handling-c programming language
PDF
14. fiile io
PDF
Module 03 File Handling in C
PPT
File in c
File handling
File handling in c
File in C language
File handling-c programming language
14. fiile io
Module 03 File Handling in C
File in c

What's hot (19)

PPTX
File Management in C
PDF
Module 5 file cp
PPT
File handling in 'C'
PPT
File handling in c
PPT
file handling1
PPT
File handling in c
PPT
File Management
PDF
Linux Bash Shell Cheat Sheet for Beginners
PPT
File handling-dutt
PPTX
File management
PDF
Linux cheat-sheet
PDF
Python - File operations & Data parsing
PPSX
1file handling
PDF
[PDF] 2021 Termux basic commands list
PDF
Unix Command-Line Cheat Sheet BTI2014
PDF
Python 3.x File Object Manipulation Cheatsheet
PPTX
Concept of file handling in c
PDF
Chapter 13.1.10
PPT
Files and Directories in PHP
File Management in C
Module 5 file cp
File handling in 'C'
File handling in c
file handling1
File handling in c
File Management
Linux Bash Shell Cheat Sheet for Beginners
File handling-dutt
File management
Linux cheat-sheet
Python - File operations & Data parsing
1file handling
[PDF] 2021 Termux basic commands list
Unix Command-Line Cheat Sheet BTI2014
Python 3.x File Object Manipulation Cheatsheet
Concept of file handling in c
Chapter 13.1.10
Files and Directories in PHP
Ad

Viewers also liked (17)

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

Similar to 2Bytesprog2 course_2014_c3_txtfiles (20)

PPTX
Files c3
PDF
Delphi L05 Files and Dialogs
DOCX
Design problem
DOCX
APPENDER.ASM;Program APPENDER.ASM Append a short message line.docx
PPT
Devry cis-170-c-i lab-7-of-7-sequential-files
PPT
Devry cis-170-c-i lab-7-of-7-sequential-files
PDF
PPT
File handling in c
PPT
Mesics lecture files in 'c'
PPTX
Presentation of file handling in C language
DOCX
Compiler Design and Construction COSC 5353Project Instructions -
PDF
Unit 5 File handling in C programming.pdf
PDF
2Bytesprog2 course_2014_c4_binaryfiles
PPTX
Lesson 1 Intro Text Files.pptx
DOC
Cis 170 c ilab 7 of 7 sequential files
PDF
void ReplaceCharInBuffer(bufferADT buffer, char oldch, char newch);.pdf
DOCX
Unit 5 dwqb ans
PPTX
working with files
PPTX
Programming Fundamentals lecture-22.pptx
Files c3
Delphi L05 Files and Dialogs
Design problem
APPENDER.ASM;Program APPENDER.ASM Append a short message line.docx
Devry cis-170-c-i lab-7-of-7-sequential-files
Devry cis-170-c-i lab-7-of-7-sequential-files
File handling in c
Mesics lecture files in 'c'
Presentation of file handling in C language
Compiler Design and Construction COSC 5353Project Instructions -
Unit 5 File handling in C programming.pdf
2Bytesprog2 course_2014_c4_binaryfiles
Lesson 1 Intro Text Files.pptx
Cis 170 c ilab 7 of 7 sequential files
void ReplaceCharInBuffer(bufferADT buffer, char oldch, char newch);.pdf
Unit 5 dwqb ans
working with files
Programming Fundamentals lecture-22.pptx

More from kinan keshkeh (20)

PDF
10 Little Tricks to Get Your Class’s Attention (and Hold It)
PDF
Simpson and lagranje dalambair math methods
PDF
Shapes and calculate (area and contour) / C++ oop concept
PDF
Shapes and calculate (area and contour) / C++ oop concept
PDF
GeneticAlgorithms_AND_CuttingWoodAlgorithm
PDF
Algorithm in discovering and correcting words errors in a dictionary or any w...
PDF
2Bytesprog2 course_2014_c9_graph
PDF
2Bytesprog2 course_2014_c8_units
PDF
2Bytesprog2 course_2014_c7_double_lists
PDF
2Bytesprog2 course_2014_c6_single linked list
PDF
2Bytesprog2 course_2014_c5_pointers
PDF
2Bytesprog2 course_2014_c2_records
PDF
2Bytesprog2 course_2014_c1_sets
PDF
2Bytesprog2 course_2014_c1_sets
PDF
2Bytesprog2 course_2014_c1_sets
PDF
2Bytesprog2 course_2014_c1_sets
PDF
2 BytesC++ course_2014_c13_ templates
PDF
2 BytesC++ course_2014_c12_ polymorphism
PDF
2 BytesC++ course_2014_c11_ inheritance
PDF
2 BytesC++ course_2014_c10_ separate compilation and namespaces
10 Little Tricks to Get Your Class’s Attention (and Hold It)
Simpson and lagranje dalambair math methods
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
GeneticAlgorithms_AND_CuttingWoodAlgorithm
Algorithm in discovering and correcting words errors in a dictionary or any w...
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c7_double_lists
2Bytesprog2 course_2014_c6_single linked list
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c10_ separate compilation and namespaces

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
history of c programming in notes for students .pptx
PPT
Introduction Database Management System for Course Database
PDF
Nekopoi APK 2025 free lastest update
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
medical staffing services at VALiNTRY
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
history of c programming in notes for students .pptx
Introduction Database Management System for Course Database
Nekopoi APK 2025 free lastest update
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Digital Strategies for Manufacturing Companies
Wondershare Filmora 15 Crack With Activation Key [2025
Reimagine Home Health with the Power of Agentic AI​
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Digital Systems & Binary Numbers (comprehensive )
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 41
medical staffing services at VALiNTRY
Odoo Companies in India – Driving Business Transformation.pdf
Designing Intelligence for the Shop Floor.pdf
System and Network Administraation Chapter 3

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