Wed, 18 Jun 1902 08:00:00 GMT
HELP: Writing & Reading RECORDs
I am taking a course that includes a unit on file structures using Pascal (that is the new of the book also). The book has an example, but it doesn't work with TP7. I have tried what my very limited knowledge of Pascal says to try and it still won't work. Would someone please share a working example of WRITE/READ of RECORDs to a file? Below is the example from the book that doesn't work. Thanks. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- TYPE Names = Record last : Packed Array [1..15] of Char; first : Packed Array [1..15] of Char; middle : Char End; Addresses = Record home : Packed Array [1..50] of Char; campus : Packed Array [1..50] of Char End; Phone = Record area_code : Integer; exchange : Integer; number : Integer End; Class = Record course_number : Packed Array [1..6] of Char; room_number : Packed Array [1..4] of Char; meeting_time : Integer End; Student = Record name : Names; address : Addresses; phone_number : Phone; classes : Array [1..6] of Class End; VAR student_file : File of Student; one_student : Student; i, j : Integer; Begin Rewrite (student_file); While Not Eof Do { Eof(Input) } Begin { input info on one student } With one_student Do Begin With name Do Begin For i := 1 to 15 Do { i : Integer } Read (last[i]); For i := 1 To 15 Do Read (first[i]); Read(middle) End; { with name } With address Do Begin For i := 1 To 50 Do Read (home[i]); For i := 1 To 50 Do Read (campus[i]) End; { with address } With phone_number Do Read (area_code, exchange, number); For i := 1 To 6 Do With classes [i] Do Begin For j := 1 To 6 Do Read (course_number [j]); For j := 1 To 4 Do Read (room_number [j]); Read (meeting_time) End { with classes [i] } End; { with one_student } { store one student's data in file buffer variable } student_file^ := one_student; {THIS IS WHERE THE FIRST ERROR OCCURS} { write one student's data in file } Put (student_file) {THIS IS WHERE THE SECOND ERROR OCCURS} End; { while } Close (student_file) End.
|