Files c4

13
Pascal Programming Language Omar ElSabek & Fayez Ghazzawi IT Engineering 3 th year – UNKNOWN Department programming II

Transcript of Files c4

Page 1: Files c4

Pascal Programming Language

Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department

programming II

Page 2: Files c4

Sets RecordFiles (Text & Binary)Pointers Linked Lists Unit

Course Index :

Page 3: Files c4

Files

Binary Files

Page 4: Files c4

Files

Two Types Of Files In Pascal:

1- Text Files2- Binary Files

Page 5: Files c4

Binary FilesConcepts

human unreadablenot editablefile content has a data typelike array of data on HD

Concepts in Pascal:Sequential (SE)

Introduction to DBMSopen before / close afterread OR writewrite = override

Page 6: Files c4

Binary FilesA binary file is a computer file which may contain any type of data, encoded in binary form for computer storage and processing purposes; for example, computer document files containing formatted text. Many binary file formats contain parts that can be interpreted as text; binary files that contain only textual data—without, for example, any formatting information—are called plain text files. In many cases, plain text files are considered to be different from binary files because binary files are made up of more than just plain text. When downloading, a completely functional program without any installer is also often called program binary, or binaries (as opposed to the source code).

from www.wikipedia.com

Page 7: Files c4

B-file:Definition and assign:

Defining Binary Files

Page 8: Files c4

Binary Files ExampleProgram test;TypeSTD = Record

Fname : string[20]; { 20 Byte}M : integer; { 2 Byte }State : Boolean; { 1 Byte }

End;Var

T,f : file of Std;VSTD : Std;

Page 9: Files c4

Writing Binary Files

Assign(f , “C:\STDfile”);Rewrite(f);For I:=1 to 100 doBegin

With VSTD doReadln ( fname , M , state);

Write (f , VSTD );End;Close(f);

Page 10: Files c4

Reading Binary Files

Reset( f );While not eof(f) doBegin

Read(f,vstd);With VSTD dowriteln ( fname , M , state);

End;Close( f );

Page 11: Files c4

Editing Binary FilesReset( f );Assign (T,’c:\temp’);Rewrite(T);While not eof(f) do Begin

Read (f , Vstd);VSTD := VSTD.M + 10 ;Write(T,VSTD);

End;Close(f);Close(T);

Page 12: Files c4

Editing Binary FilesReset( T );Rewrite (f);While not eof(T) doBegin

Read (T , VSTD);Write(f , VSTD);

End;Close (T);Close (f);Rewrite(T); Close(T);

Page 13: Files c4

We’re finished

for today !