home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / charin.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.8 KB  |  72 lines

  1.                                        -- Chapter 14 - Program 4
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CharIn is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    My_File  : FILE_TYPE;
  11.    One_Char : CHARACTER;
  12.  
  13. begin
  14.  
  15.    open(My_File,In_File,"CHARACTS.TXT");
  16.  
  17.    loop       -- Read one character at a time and display it
  18.       exit when End_Of_File(My_File);
  19.       Get(My_File,One_Char);
  20.       Put(One_Char);
  21.    end loop;
  22.    New_Line(2);
  23.  
  24.    Reset(My_File);  -- Reset and start over with the same file
  25.  
  26.    loop       -- Read and display but search for End of lines
  27.       exit when End_Of_File(My_File);
  28.       Get(My_File,One_Char);
  29.       if End_Of_Line(My_File) then
  30.          Put("<--- End of line found");
  31.          New_Line;
  32.       else
  33.          Put(One_Char);
  34.       end if;
  35.    end loop;
  36.    New_Line;
  37.  
  38.    Reset(My_File);  -- Reset and start over the third time
  39.  
  40.               -- Read and display but search for End of lines
  41.    loop       -- using a look ahead method
  42.       exit when End_Of_File(My_File);
  43.       Get(My_File,One_Char);
  44.       Put(One_Char);
  45.       if End_Of_Line(My_File) then
  46.          Put("<--- End of line found");
  47.          New_Line;
  48.       end if;
  49.    end loop;
  50.  
  51.    Close(My_File);
  52.  
  53. end CharIn;
  54.  
  55.  
  56.  
  57.  
  58. -- Result of execution
  59.  
  60. -- (Note; the first line is a full 80 columns wide.)
  61. -- This line goes to the CHARACTS.TXT file.This line goes to...
  62. -- This line goes to the CHARACTS.TXT file.
  63. --
  64. -- This line goes to the CHARACTS.TXT file<--- End of line found
  65. -- This line goes to the CHARACTS.TXT file<--- End of line found
  66. -- This line goes to the CHARACTS.TXT file<--- End of line found
  67. --
  68. -- This line goes to the CHARACTS.TXT file.<--- End of line found
  69. -- This line goes to the CHARACTS.TXT file.<--- End of line found
  70. -- This line goes to the CHARACTS.TXT file.<--- End of line found
  71.  
  72.