该函数的调用方式如下所示:
INTEGER*4 getc status = getc( char ) |
|||
char |
字符 |
输出 |
下一个字符 |
返回值 |
INTEGER*4 |
输出 |
status=0:OK status=-1:文件结束 status>0:系统错误代码或 f95 I/O 错误代码 |
示例:使用 getc 获取从键盘输入的每个字符;请注意 Ctrl-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 |
编译之后,运行以上源代码的样例如下:
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% |
对于逻辑单元,请勿将正常的 Fortran 输入与 getc() 混在一起。