Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pascal Programming Files and Text (an intro). Pascal Programming Files... Data files need to be retained in secondary memory. The machine memory is random.

Similar presentations


Presentation on theme: "Pascal Programming Files and Text (an intro). Pascal Programming Files... Data files need to be retained in secondary memory. The machine memory is random."— Presentation transcript:

1 Pascal Programming Files and Text (an intro)

2 Pascal Programming Files... Data files need to be retained in secondary memory. The machine memory is random access (RAM) and volatile—it is erased by turning off the machine. Secondary memory could be the hard disk drive, a removable disk or a R/W CD ROM.

3 Pascal Programming Thus, file can be defined as a collection of data, named and stored. In DOS, the file naming convention is 8/3 or XXXXXXXX.XXX. File being processed by Pascal have a name for storage and a file variable name. A file variable must be declared.

4 Pascal Programming File variables......cannot be used in assignment statements....have predefined procedures for processing....have predefined syntax. assign – the predefined procedure, calls the file. –Assign (File, ‘data.txt’) This is the first step in working with a saved file.

5 Pascal Programming To read or write to a file, it must be opened. –assign (File, ‘data.txt’); –rewrite (File); Write and writeln statements write to the file. –writeln (File, ‘new data’) Remember, File is a file variable name and not a variable to be written out. After use, files must be closed. –close (File) To add to a file, append. –append (File)

6 Pascal Programming Printing... Turbo Pascal writes to the printer like it writes to a file. –e g: –assign (File, ‘PRN’); –rewrite (file); –writeln (File, ‘data.txt’); –close (File);

7 Pascal Programming reset opens a file for reading. –assign (File, ‘data.txt’); –reset (File); read and readln will read the content of the file. The eof (end of file) function will allow a read statement to proceed to the end of the file. –eof (File)


Download ppt "Pascal Programming Files and Text (an intro). Pascal Programming Files... Data files need to be retained in secondary memory. The machine memory is random."

Similar presentations


Ads by Google