home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TURBO.ZIP / TYPEFILE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1984-06-12  |  2.4 KB  |  81 lines

  1. PROGRAM TYPEFILE;
  2.  
  3. { This turbo pascal program shows how to read, and write a file. }
  4. { MALCOLM MCCORQUODALE III, HOUSTON, TEXAS  JUNE 1984}
  5.  
  6. VAR
  7.      FILE1, FILE2 : TEXT;          { File variables }
  8.      PRTLINE      : STRING[78];    { Read into this variable and print it }
  9.      FILENAME1,
  10.      FILENAME2    : STRING[14];    { Name of source and dest files }
  11.  
  12. {1------------------------------------------------}
  13.  
  14. PROCEDURE GET_FILE_NAMES;
  15. { Ask the user what file to read from and write to, }
  16. { then open those files. }
  17. BEGIN
  18.      WRITELN ('Enter name of file to read');   { Ask question  }
  19.      READLN (FILENAME1);                       { Get answer    }
  20.      ASSIGN (FILE1,FILENAME1);     { Tell computer the answer  }
  21.      RESET (FILE1);                { Open the file for reading }
  22.  
  23.      WRITELN ('Enter name of file to write');  { Ask question  }
  24.      READLN (FILENAME2);                       { Get answer    }
  25.      ASSIGN (FILE2,FILENAME2);     { Tell computer the answer  }
  26.      REWRITE (FILE2);              { Open the file for writing }
  27. END;
  28.  
  29. {1------------------------------------------------}
  30.  
  31. PROCEDURE READ_AND_PRINT_FILE;
  32. { Read and print each record read along with it's record number }
  33. VAR
  34.      RECCNT,                  { Record counter }
  35.      SCRCNT : INTEGER;        { Counts records on screen }
  36.  
  37. {2------------------------------------------------}
  38.  
  39. PROCEDURE NEW_PAGE;
  40. VAR
  41.      CH : CHAR;
  42. BEGIN
  43.        WRITELN ('Hit ENTER to continue');
  44.        READLN (CH);             { Wait until a key is hit }
  45.        CLRSCR;                  { Clear the screen }
  46.        SCRCNT := 0;
  47. END;
  48.  
  49. {2------------------------------------------------}
  50.  
  51. BEGIN
  52.      RECCNT := 1;
  53.      SCRCNT := 0;
  54.      WHILE NOT EOF (FILE1) DO      { As long as there are records DO }
  55.      BEGIN
  56.           READLN (FILE1,PRTLINE);    { Read the file }
  57.           WRITELN (RECCNT,PRTLINE);  { Write record and number on screen }
  58.           WRITELN (FILE2,PRTLINE);   { Write record to other disk file }
  59.           RECCNT := RECCNT + 1;      { Increment record counter }
  60.           SCRCNT := SCRCNT + 1;
  61.           IF SCRCNT = 20 THEN NEW_PAGE;
  62.           END;
  63. END;
  64.  
  65. {1------------------------------------------------}
  66.  
  67. PROCEDURE CLOSE_FILES;
  68. { Close the files we have opened }
  69. BEGIN
  70.      CLOSE(FILE1);
  71.      CLOSE(FILE2);
  72. END;
  73.  
  74. {1------------------------------------------------}
  75.  
  76. BEGIN
  77.      GET_FILE_NAMES;
  78.      READ_AND_PRINT_FILE;
  79.      CLOSE_FILES;
  80. END.
  81.