home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / TBTREE16.ZIP / EXAM4.PAS < prev    next >
Pascal/Delphi Source File  |  1989-07-12  |  3KB  |  113 lines

  1. (* EXAM4.PAS *)
  2.  
  3. program driver;
  4. {$R+}
  5.  
  6. uses
  7.     Exam0,
  8.     FileBuff,
  9.     FileDecs;
  10.  
  11. var
  12.     dataFile  : FnString;                       (* holds file name strings *)
  13.     cnt : 1 .. TOTALRECORDS;
  14.     str : TestString;
  15.     thisFile : Text;
  16.  
  17.  
  18. (* This procedure creates the text file but does not write any data to it.   *)
  19.  
  20. procedure InitFiles;
  21.  
  22.     begin
  23.     dataFile := 'myFile1.txt';
  24.     RewriteTextFile(dataFile,thisFile);
  25.     end;
  26.  
  27.  
  28. (* This routine creates a random string and is used for creating strings to
  29. demonstrate the handling of strings in text file                            *)
  30.  
  31. procedure CreateRandomString(var str : TestString);
  32.  
  33. var
  34.     chrCnt : 1 .. TESTSTRINGSIZE;
  35.     tss : Byte;
  36.  
  37.     begin
  38.     str := '';
  39.     for chrCnt := 1 to TESTSTRINGSIZE do
  40.         begin
  41.         str[chrCnt] := Chr(Random(25) + 65);
  42.         end;
  43.     tss := TESTSTRINGSIZE;
  44.     Move(tss,str,1);
  45.     end;
  46.  
  47.  
  48. (*****************************************************************************)
  49. (*                                                                           *)
  50. (*                         M A I N      P R O G R A M                        *)
  51. (*                                                                           *)
  52. (*****************************************************************************)
  53.  
  54. begin
  55.  
  56. Writeln('Creating Text File ...');                  (* just a note so you can
  57.                                                       follow along           *)
  58.  
  59. InitFiles;
  60.  
  61.  
  62. Writeln('Creating and storing data ... this may take a minute ...');
  63.                                                    (* just a note so you can
  64.                                                       follow along           *)
  65.  
  66.     (* the following loop will create 15 records which will be inserted into
  67.        the text file.                                                        *)
  68.  
  69.  
  70. for cnt := 1 to TOTALRECORDS do
  71.     begin
  72.     CreateRandomString(str);
  73.     Writeln(str);
  74.     OpenTextFile(dataFile,thisFile);
  75.     Writeln(thisFile,str);
  76.     end;
  77.  
  78. Writeln;
  79. Writeln;
  80.  
  81. CloseFile(dataFile);                               (* go ahead and close it *)
  82.  
  83. for cnt := 1 to TOTALRECORDS do
  84.     begin
  85.     CreateRandomString(str);
  86.     Writeln(str);
  87.     AppendTextFile(dataFile,thisFile);
  88.     Writeln(thisFile,str);
  89.     end;
  90.  
  91. Writeln;
  92. Writeln;
  93.  
  94. str := '';
  95.  
  96. CloseFile(dataFile);
  97.  
  98. OpenTextFile(dataFile,thisFile);                          (* open for input *)
  99. while not Eof(thisFile) do
  100.     begin
  101.     OpenTextFile(dataFile,thisFile);
  102.     Readln(thisFile,str);
  103.     Writeln(str);
  104.     end;
  105.  
  106. Writeln('Closing Files ...');                      (* just a note so you can
  107.                                                       follow along           *)
  108.  
  109. CloseAllFiles;                               (* Close the files to clean up. *)
  110.  
  111.  
  112. end.
  113.