Pascal Programming Today Chapter 11 1 Chapter 11
Pascal Programming Today Chapter 11 2 »Data are usually stored in text files. »Text files save data one by one in the format of a sequence of characters.
Pascal Programming Today Chapter 11 3 »Each line in a text file is ended with an end-of-line marker. »An end-of-file marker, indicates the end of the file, is placed at the end of the file.
Pascal Programming Today Chapter 11 4 »Procedures involved in writing data to files: –assign –rewrite –write –close
Pascal Programming Today Chapter 11 5 »Procedures involved in reading data from files: –assign –reset –read –close
Pascal Programming Today Chapter 11 6 »Variables of type text are used to identify files. Syntax of declaring text files var : text;
Pascal Programming Today Chapter 11 7 »Procedure assign associates file variables with files in secondary storage. Syntax of the procedure assign assign(, ) It is a user-defined identifier declared as type text.
Pascal Programming Today Chapter 11 8 »Procedure assign associates file variables with files in secondary storage. Syntax of the procedure assign assign(, ) May be a string constant of the file name or a string variable holding the file name.
Pascal Programming Today Chapter 11 9 »Procedure rewrite prepares files for writing data to them. »Original data will be lost when procedure rewrite is applied to the files.
Pascal Programming Today Chapter Syntax of the procedure rewrite rewrite( )
Pascal Programming Today Chapter »Procedure reset prepares files for reading data from them. Syntax of the procedure reset reset( )
Pascal Programming Today Chapter Differences between procedures rewrite and reset
Pascal Programming Today Chapter »Procedure close is used to close a file. Syntax of the procedure close close( )
Pascal Programming Today Chapter Summary of procedures of writing data to and reading data from a file
Pascal Programming Today Chapter »Procedures writeln and write can save data to files.
Pascal Programming Today Chapter Syntax of the procedures writeln and write for writing data to files writeln(,,,...) or write(,,,...)
Pascal Programming Today Chapter »File variables must be supplied in front of the output lists, otherwise data will be displayed on screen only. »Data written to files can be formatted in similar way as data displayed on screen.
Pascal Programming Today Chapter »Procedure writeln will add an end-of-line marker after a list of output items to files while procedure write will not.
Pascal Programming Today Chapter »Procedures readln and read can obtain data from files.
Pascal Programming Today Chapter Syntax of the procedures readln and read for reading data from files readln(,,,...) or read(,,,...)
Pascal Programming Today Chapter »File variables must be supplied in front of the variable lists, otherwise data will be read from keyboard. »Result of reading depends on the maximum width and the types of the variables.
Pascal Programming Today Chapter Results of reading variables of different widths and types
Pascal Programming Today Chapter »Procedure readln will advance the pointer after the end-of-line marker after reading while procedure read will advance to pass the read data only.
Pascal Programming Today Chapter Assume the contents of a file ‘Exampl1_6.txt’ is 210 220 230 240 250 260
Pascal Programming Today Chapter var S : string[5]; T, U : string[2]; C, D : char; M, N : integer; R : real; FileVariable : text; Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, S, T); readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, S, T); readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, S, T); readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, S, T); readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, S, T); readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin readln(FileVariable, C); read(FileVariable, M); readln(FileVariable,U); readln(FileVariable, D); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin read(FileVariable, M); readln(FileVariable,U); readln(FileVariable, D); read(FileVariable, N); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter begin readln(FileVariable,U); readln(FileVariable, D); read(FileVariable, N); readln(FileVariable, R); Output After the execution of the above program segment, the contents of the variables are as shown below.
Pascal Programming Today Chapter »The eof function returns the value TRUE if the pointer is currently pointing at the end-of-file marker; otherwise FASLE. Syntax of the eof function eof( )
Pascal Programming Today Chapter »To update a sequential file means to –append data to the file (i.e. add data to the end of the file)
Pascal Programming Today Chapter –insert data to the file (i.e. add data to the proper position of the file so that the order of the data can be maintained) –delete data from the file (i.e. remove data from the file)
Pascal Programming Today Chapter –edit data of the file (i.e. modify the data)