Previous topic |
Next topic |
Ada Home Page |
Index
TEXT_IO
To work with text files, an Ada program must import the TEXT_IO package.
TEXT_IO provides:
- procedures for reading and writing characters and strings
- GET, PUT, GET_LINE, PUT_LINE
- generic packages for I/O of integers, floats, enumeration types
- since characters typed by a user need to be converted to the
appropriate numeric or enumeration value
- procedures and functions to detect or impose the
page/line/character structure
Page - line - character
Procedures to create the page/line/character structure:
- go to a given character position:
- SET_COL - go to nominated column in output file
(on next line, if already past that position on this line)
- go to a given line:
- NEW_LINE - go to next line of output
- SET_LINE - go to nominated line in output file
- go to next page:
Procedures to recognise the page/line/character structure:
- SKIP_LINE - go to start of next line of input
- SKIP_PAGE - go to start of next page of input
Functions to recognise position within the page/line/character structure:
- PAGE - what page number are we up to in the file?
- LINE - what line number are we up to on the page?
- COL - what character position are we up to on the line?
Example:
SET_LINE (2);
SET_COL (30); PUT ("Student Results Report");
SET_LINE (4);
SET_COL ( 5); PUT ("Student name");
SET_COL (35); PUT ("Assignments");
SET_COL (50); PUT ("Exams");
SET_COL (65); PUT ("Average");
SET_LINE (6);
Line Length
For output files, you can define automatic line and page lengths
SET_LINE_LENGTH:
- EOL generated automatically when limit reached
- default is 0 (unconstrained)
Example:
SET_LINE_LENGTH (30);
for i in 1 .. 20 loop
PUT (i**2, width => 5);
end loop;
' 1 4 9 16 25 36'
' 49 64 81 100 121 144'
' 169 196 225 256 289 324'
' 361 400'
SET_PAGE_LENGTH is analogous
Previous topic |
Next topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 22 Feb 96