A C program can use SYSDTA as follows:
An open function (
fopen
/fopen64
,freopen
/freopen64
,open
/open64
) is used to open a file with the name "(SYSDTA)" or "(SYSTERM)" for reading. The file pointer returned by the open function then serves as an argument for a subsequent input function.Example
FILE *fp; fp = fopen("(SYSDTA)", "r"); fgetc(fp);
For input functions, the file pointer
stdin
or the file descriptor 0 is specified as the file argument.Examples
fgetc(stdin);
read(0, buf, n);
Input functions that read from
stdin
by default (e.g.scanf
,getchar
,gets
) are used.
If input is to be from a cataloged file instead of the data terminal, there are two ways of doing this:
If a parameter line was requested with PARAMETER-PROMPTING=YES (in the RUNTIME-OPTIONS compiler option), this parameter line can be used to redirect the standard input (file pointer
stdin
or file descriptor 0) to a cataloged file. Please refer to your C and C++ User Guides.This reassignment does not have an effect on files that were opened with the names "(SYSDTA)" or "(SYSTERM)". Input from files with this name is still expected from the data terminal.
By using the command ASSIGN-SYSDTA filename before program start.
For all input functions, input data is then expected from the assigned file.
The following must be observed when an assignment is made with the
ASSIGN-SYSDTA command:After the program is executed, the internal record pointer is positioned after the last record that was read or at the end of the file. If the file is to be read again from the beginning in a subsequent program run, a new ASSIGN-SYSDTA command must be issued before the program is started.
If PARAMETER-PROMPTING=YES was selected (in the RUNTIME-OPTIONS option), the first record of the assigned file is interpreted as a parameter line for the main function.
Note
If no other end criterion for reading has been declared in the C program, the EOF or WEOF condition for inputs at the data terminal can be provoked by pressing the K2 key and entering the EOF and RESUME-PROGRAM commands.