xref: /csrg-svn/lib/libc/stdio/getc.3 (revision 48351)
1*48351Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
246090Sbostic.\" All rights reserved.
320325Smckusick.\"
446090Sbostic.\" This code is derived from software contributed to Berkeley by
546090Sbostic.\" Chris Torek.
646090Sbostic.\" %sccs.include.redist.man%
746090Sbostic.\"
8*48351Scael.\"     @(#)getc.3	6.7 (Berkeley) 04/19/91
946090Sbostic.\"
10*48351Scael.Dd
11*48351Scael.Dt GETC 3
12*48351Scael.Os
13*48351Scael.Sh NAME
14*48351Scael.Nm fgetc ,
15*48351Scael.Nm getc ,
16*48351Scael.Nm getchar ,
17*48351Scael.Nm getw
18*48351Scael.Nd get next character or word from input stream
19*48351Scael.Sh SYNOPSIS
20*48351Scael.Fd #include <stdio.h>
21*48351Scael.Ft int
22*48351Scael.Fn fgetc "FILE *stream"
23*48351Scael.Ft int
24*48351Scael.Fn getc "FILE *stream"
25*48351Scael.Ft int
26*48351Scael.Fn getchar
27*48351Scael.Ft int
28*48351Scael.Fn getw "FILE *stream"
29*48351Scael.Sh DESCRIPTION
30*48351ScaelThe
31*48351Scael.Fn fgetc
32*48351Scaelfunction
33*48351Scaelobtains the next input character (if present) from the stream pointed at by
34*48351Scael.Fa stream ,
35*48351Scaelor the next character pushed back on the stream via
36*48351Scael.Xr ungetc .
37*48351Scael.Pp
38*48351ScaelThe
39*48351Scael.Fn getc
40*48351Scaelfunction
4146090Sbosticacts essentially identically to
42*48351Scael.Fn fgetc ,
4346090Sbosticbut is a macro that expands in-line.
44*48351Scael.Pp
45*48351ScaelThe
46*48351Scael.Fn getchar
47*48351Scaelfunction
48*48351Scaelis equivalent to:
49*48351Scaelgetc with the argument stdin.
50*48351Scael.Pp
51*48351ScaelThe
52*48351Scael.Fn getw
53*48351Scaelfunction
54*48351Scaelobtains the next
55*48351Scael.Em int
56*48351Scael(if present)
57*48351Scaelfrom the stream pointed at by
58*48351Scael.Fa stream .
59*48351Scael.Sh RETURN VALUES
60*48351ScaelIf successful, these routines return the next requested object
61*48351Scaelfrom the
62*48351Scael.Fa stream .
63*48351ScaelIf the stream is at end-of-file or a read error occurs,
64*48351Scaelthe routines return
65*48351Scael.Dv EOF .
66*48351ScaelThe routines
67*48351Scael.Xr feof 3
6820325Smckusickand
69*48351Scael.Xr ferror 3
70*48351Scaelmust be used to distinguish between end-of-file and error.
7146090SbosticIf an error occurs, the global variable
72*48351Scael.Va errno
7346090Sbosticis set to indicate the error.
7446090SbosticThe end-of-file condition is remembered, even on a terminal, and all
7546090Sbosticsubsequent attempts to read will return
76*48351Scael.Dv EOF
7728176Skarelsuntil the condition is cleared with
78*48351Scael.Xr clearerr .
79*48351Scael.Sh SEE ALSO
80*48351Scael.Xr ferror 3 ,
81*48351Scael.Xr fread 3 ,
82*48351Scael.Xr fopen 3 ,
83*48351Scael.Xr putc 3 ,
84*48351Scael.Xr ungetc 3
85*48351Scael.Sh STANDARDS
86*48351ScaelThe
87*48351Scael.Fn fgetc ,
88*48351Scael.Fn getc
89*48351Scaeland
90*48351Scael.Fn getchar
91*48351Scaelfunctions
92*48351Scaelconform to
93*48351Scael.St -ansiC .
94*48351Scael.Sh BUGS
9546090SbosticSince
96*48351Scael.Dv EOF
9746090Sbosticis a valid integer value,
98*48351Scael.Xr feof
9946090Sbosticand
100*48351Scael.Xr ferror
10146090Sbosticmust be used to check for failure after calling
102*48351Scael.Fn getw .
10346090SbosticThe size and byte order of an
104*48351Scael.Em int
10546090Sbosticvaries from one machine to another, and
106*48351Scael.Fn getw
10746090Sbosticis not recommended for portable applications.
108*48351Scael.Pp
109