1FGETC(3) Linux Programmer's Manual FGETC(3)
2
3
4
6 fgetc, fgets, getc, getchar, ungetc - input of characters and strings
7
9 #include <stdio.h>
10
11 int fgetc(FILE *stream);
12
13 char *fgets(char *s, int size, FILE *stream);
14
15 int getc(FILE *stream);
16
17 int getchar(void);
18
19 int ungetc(int c, FILE *stream);
20
22 fgetc() reads the next character from stream and returns it as an un‐
23 signed char cast to an int, or EOF on end of file or error.
24
25 getc() is equivalent to fgetc() except that it may be implemented as a
26 macro which evaluates stream more than once.
27
28 getchar() is equivalent to getc(stdin).
29
30 fgets() reads in at most one less than size characters from stream and
31 stores them into the buffer pointed to by s. Reading stops after an
32 EOF or a newline. If a newline is read, it is stored into the buffer.
33 A terminating null byte ('\0') is stored after the last character in
34 the buffer.
35
36 ungetc() pushes c back to stream, cast to unsigned char, where it is
37 available for subsequent read operations. Pushed-back characters will
38 be returned in reverse order; only one pushback is guaranteed.
39
40 Calls to the functions described here can be mixed with each other and
41 with calls to other input functions from the stdio library for the same
42 input stream.
43
44 For nonlocking counterparts, see unlocked_stdio(3).
45
47 fgetc(), getc(), and getchar() return the character read as an unsigned
48 char cast to an int or EOF on end of file or error.
49
50 fgets() returns s on success, and NULL on error or when end of file oc‐
51 curs while no characters have been read.
52
53 ungetc() returns c on success, or EOF on error.
54
56 For an explanation of the terms used in this section, see at‐
57 tributes(7).
58
59 ┌──────────────────────────┬───────────────┬─────────┐
60 │Interface │ Attribute │ Value │
61 ├──────────────────────────┼───────────────┼─────────┤
62 │fgetc(), fgets(), getc(), │ Thread safety │ MT-Safe │
63 │getchar(), ungetc() │ │ │
64 └──────────────────────────┴───────────────┴─────────┘
65
67 POSIX.1-2001, POSIX.1-2008, C89, C99.
68
69 It is not advisable to mix calls to input functions from the stdio li‐
70 brary with low-level calls to read(2) for the file descriptor associ‐
71 ated with the input stream; the results will be undefined and very
72 probably not what you want.
73
75 read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
76 fseek(3), getline(3), gets(3), getwchar(3), puts(3), scanf(3),
77 ungetwc(3), unlocked_stdio(3), feature_test_macros(7)
78
80 This page is part of release 5.10 of the Linux man-pages project. A
81 description of the project, information about reporting bugs, and the
82 latest version of this page, can be found at
83 https://www.kernel.org/doc/man-pages/.
84
85
86
87GNU 2020-12-21 FGETC(3)