| 1 | .\" @(#)getc.3 6.2 (Berkeley) %G% |
| 2 | .\" |
| 3 | .TH GETC 3S "" |
| 4 | .AT 3 |
| 5 | .SH NAME |
| 6 | getc, getchar, fgetc, getw \- get character or word from stream |
| 7 | .SH SYNOPSIS |
| 8 | .B #include <stdio.h> |
| 9 | .PP |
| 10 | .B int getc(stream) |
| 11 | .br |
| 12 | .SM |
| 13 | .B FILE |
| 14 | .B *stream; |
| 15 | .PP |
| 16 | .B int getchar() |
| 17 | .PP |
| 18 | .B int fgetc(stream) |
| 19 | .br |
| 20 | .SM |
| 21 | .B FILE |
| 22 | .B *stream; |
| 23 | .PP |
| 24 | .B int getw(stream) |
| 25 | .br |
| 26 | .SM |
| 27 | .B FILE |
| 28 | .B *stream; |
| 29 | .SH DESCRIPTION |
| 30 | .I Getc |
| 31 | returns the next character from the named input |
| 32 | .IR stream . |
| 33 | .PP |
| 34 | .IR Getchar () |
| 35 | is identical to |
| 36 | .IR getc ( stdin ) . |
| 37 | .PP |
| 38 | .I Fgetc |
| 39 | behaves like |
| 40 | .IR getc , |
| 41 | but is a genuine function, not a macro; |
| 42 | it may be used to save object text. |
| 43 | .PP |
| 44 | .I Getw |
| 45 | returns the next |
| 46 | .B int |
| 47 | (a 32-bit integer on a VAX-11) from the named input |
| 48 | .IR stream . |
| 49 | It returns the constant |
| 50 | .SM |
| 51 | .B EOF |
| 52 | upon end of file or error, but since that is a good |
| 53 | integer value, |
| 54 | .I feof |
| 55 | and |
| 56 | .IR ferror (3S) |
| 57 | should be used to check the success of |
| 58 | .IR getw . |
| 59 | .I Getw |
| 60 | assumes no special alignment in the file. |
| 61 | .SH "SEE ALSO" |
| 62 | clearerr(3S), |
| 63 | fopen(3S), |
| 64 | putc(3S), |
| 65 | gets(3S), |
| 66 | scanf(3S), |
| 67 | fread(3S), |
| 68 | ungetc(3S) |
| 69 | .SH DIAGNOSTICS |
| 70 | These functions return the integer constant |
| 71 | .SM |
| 72 | .B EOF |
| 73 | at end of file, upon read error, |
| 74 | or if an attempt is made to read a file not opened by |
| 75 | .IR fopen . |
| 76 | The end-of-file condition is remembered, |
| 77 | even on a terminal, |
| 78 | and all subsequent attempts to read will return |
| 79 | .B EOF |
| 80 | until the condition is cleared with |
| 81 | .IR clearerr (3S). |
| 82 | .SH BUGS |
| 83 | Because it is implemented as a macro, |
| 84 | .I getc |
| 85 | treats a |
| 86 | .I stream |
| 87 | argument with side effects incorrectly. |
| 88 | In particular, |
| 89 | `getc(*f++);' |
| 90 | doesn't work sensibly. |