xref: /original-bsd/lib/libc/stdio/getc.3 (revision e0399a72)
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\" %sccs.include.redist.man%
7.\"
8.\"     @(#)getc.3	6.7 (Berkeley) 04/19/91
9.\"
10.Dd
11.Dt GETC 3
12.Os
13.Sh NAME
14.Nm fgetc ,
15.Nm getc ,
16.Nm getchar ,
17.Nm getw
18.Nd get next character or word from input stream
19.Sh SYNOPSIS
20.Fd #include <stdio.h>
21.Ft int
22.Fn fgetc "FILE *stream"
23.Ft int
24.Fn getc "FILE *stream"
25.Ft int
26.Fn getchar
27.Ft int
28.Fn getw "FILE *stream"
29.Sh DESCRIPTION
30The
31.Fn fgetc
32function
33obtains the next input character (if present) from the stream pointed at by
34.Fa stream ,
35or the next character pushed back on the stream via
36.Xr ungetc .
37.Pp
38The
39.Fn getc
40function
41acts essentially identically to
42.Fn fgetc ,
43but is a macro that expands in-line.
44.Pp
45The
46.Fn getchar
47function
48is equivalent to:
49getc with the argument stdin.
50.Pp
51The
52.Fn getw
53function
54obtains the next
55.Em int
56(if present)
57from the stream pointed at by
58.Fa stream .
59.Sh RETURN VALUES
60If successful, these routines return the next requested object
61from the
62.Fa stream .
63If the stream is at end-of-file or a read error occurs,
64the routines return
65.Dv EOF .
66The routines
67.Xr feof 3
68and
69.Xr ferror 3
70must be used to distinguish between end-of-file and error.
71If an error occurs, the global variable
72.Va errno
73is set to indicate the error.
74The end-of-file condition is remembered, even on a terminal, and all
75subsequent attempts to read will return
76.Dv EOF
77until the condition is cleared with
78.Xr clearerr .
79.Sh SEE ALSO
80.Xr ferror 3 ,
81.Xr fread 3 ,
82.Xr fopen 3 ,
83.Xr putc 3 ,
84.Xr ungetc 3
85.Sh STANDARDS
86The
87.Fn fgetc ,
88.Fn getc
89and
90.Fn getchar
91functions
92conform to
93.St -ansiC .
94.Sh BUGS
95Since
96.Dv EOF
97is a valid integer value,
98.Xr feof
99and
100.Xr ferror
101must be used to check for failure after calling
102.Fn getw .
103The size and byte order of an
104.Em int
105varies from one machine to another, and
106.Fn getw
107is not recommended for portable applications.
108.Pp
109