HP C/iX Library Reference Manual (30026-90004)
Chapter 2 17
HP C/iX Library Input and Output
HP C/iX Library Input and Output
pointer to a structure type called FILE. The FILE structure, which is defined in <stdio.h>,
contains several fields to hold information about the pointer to the buffer, the file
descriptor, and the file access mode.
The FILE structures provide the operating system with bookkeeping information, but your
only means of access to the stream is the pointer to the FILE structure (called a file
pointer). The file pointer, which you must declare in your program, holds the stream
identifier returned by the fopen function. You use the file pointer to read from, write to, or
close the stream.
For unbuffered functions, you must associate a file with a file descriptor by using the open
function. A file descriptor is a unique integer that identifies a particular file. This file
descriptor is also contained in the FILE structure returned by fopen.
Standard Files
There are three constant pointers defined in stdio.h> that designate standard C streams.
These streams are automatically opened by the C language startup routines. The standard
stream designators are:
The stdin stream is opened for reading. Your program only receives data from the stdin
stream. It cannot write data to this stream. The stdin stream defaults to the standard
MPE file $STDINX. If you run your program in interactive mode, the input device is
normally a keyboard.
The stdout stream is opened for writing. Your program only outputs data to the stdout
stream. It cannot read data from this stream. The stdout stream defaults to the standard
MPE file $STDLIST. If you run your program in an interactive mode, the output device is
normally your terminal.
The stderr stream is also opened for writing. Your program cannot read data from this
stream. Like stdout, this stream defaults to the standard MPE file $STDLIST. For
interactive programs, this file is normally your terminal. The stderr stream is used to
print error and warning messages when an erroneous condition is detected in your
program. The stderr stream is unbuffered by default. An unbuffered stream transfers
data to its destination one byte at a time.
Reading from stdin in Interactive and Batch Modes
When reading from stdin in interactive mode using fgets, gets, fscanf, scanf,orfread,
the input text stream is not padded with trailing blanks.
When reading from stdin in batch mode using fgets, gets, fscanf, scanf, or fread, the
input stream may or may not be padded with trailing blanks before being terminated with
Table 2-1. Standard Stream Designators
Stream Function Default
stdin Standard Input $STDINX
stdout Standard Output $STDLIST
stderr Standard Error $STDLIST