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

  1.                                        -- Chapter 14 - Program 5
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure StringIn is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    My_File   : FILE_TYPE;
  11.    My_String : STRING(1..10);
  12.  
  13. begin
  14.  
  15.    Open(My_File,In_File,"CHARACTS.TXT");
  16.  
  17.    loop       -- Read one string at a time and display it
  18.       exit when End_Of_File(My_File);
  19.       Get(My_File,My_String);
  20.       Put(My_String);
  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,My_String);
  29.       Put(My_String);
  30.       if End_Of_Line(My_File) then
  31.          Put_Line("<--- End of line found");
  32.       else
  33.          Put_Line("<--- 10 characters");
  34.       end if;
  35.    end loop;
  36.    New_Line;
  37.  
  38.    Close(My_File);
  39.  
  40. end StringIn;
  41.  
  42.  
  43.  
  44.  
  45. -- Result of execution
  46.  
  47. -- (Note; The first line is a full 80 columns wide.)
  48. -- This line goes to the CHARACTS.TXT file.This line goes to ...
  49. -- This line goes to the CHARACTS.TXT file.
  50. --
  51. -- This line <--- 10 characters
  52. -- goes to th<--- 10 characters
  53. -- e CHARACTS<--- 10 characters
  54. -- .TXT file.<--- End of line found
  55. -- This line <--- 10 characters
  56. -- goes to th<--- 10 characters
  57. -- e CHARACTS<--- 10 characters
  58. -- .TXT file.<--- End of line found
  59. -- This line <--- 10 characters
  60. -- goes to th<--- 10 characters
  61. -- e CHARACTS<--- 10 characters
  62. -- .TXT file.<--- End of line found
  63.  
  64.