INTEGER*4 fgetc status = fgetc( lunit, char ) |
|||
---|---|---|---|
lunit |
INTEGER*4 |
Input |
Logical unit |
char |
character |
Output |
Next character |
Return value |
INTEGER*4 |
Output |
status=-1: End of File status>0: System error code or f77 I/O error code |
Example: fgetc gets each character from tfgetc.data; note the linefeeds (Octal 012):
character char INTEGER*4 fgetc, status open( unit=1, file='tfgetc.data' ) status = 0 do while ( status .eq. 0 ) status = fgetc( 1, char ) write(*, '(i3, o4.3)') status, char end do end
After compiling, a sample run of the above source is:
demo% cat tfgetc.data ab yz demo% a.out 0 141 `a' read 0 142 `b' read 0 012 linefeed read 0 171 `y' read 0 172 `z' read 0 012 linefeed read -1 012 CONTROL-D read demo%
For any logical unit, do not mix normal FORTRAN input with fgetc().
See also: getc(3S), intro(2), and perror(3F).