The function is called by:
INTEGER*4 getc status = getc( char ) |
|||
char |
character |
Output |
Next character |
Return value |
INTEGER*4 |
Output |
status=0: OK status=-1: End of file status>0: System error code or f95 I/O error code |
Example: getc gets each character from the keyboard; note the Control-D (^D):
character char INTEGER*4 getc, status status = 0 do while ( status .eq. 0 ) status = getc( char ) write(*, ’(i3, o4.3)’) status, char end do end |
After compiling, a sample run of the above source is:
demo% a.out ab Program reads letters typed in 0 141 Program outputs status and octal value of the characters entered 0 142 141 represents ’a’, 142 is ’b’ 0 012 012 represents the RETURN key ^D terminated by a CONTROL-D. -1 377 Next attempt to read returns CONTROL-D demo% |
For any logical unit, do not mix normal Fortran input with getc().