1fgetc(3)                   Library Functions Manual                   fgetc(3)
2
3
4

NAME

6       fgetc, fgets, getc, getchar, ungetc - input of characters and strings
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       int fgetc(FILE *stream);
15       int getc(FILE *stream);
16       int getchar(void);
17
18       char *fgets(char s[restrict .size], int size, FILE *restrict stream);
19
20       int ungetc(int c, FILE *stream);
21

DESCRIPTION

23       fgetc()  reads  the next character from stream and returns it as an un‐
24       signed char cast to an int, or EOF on end of file or error.
25
26       getc() is equivalent to fgetc() except that it may be implemented as  a
27       macro which evaluates stream more than once.
28
29       getchar() is equivalent to getc(stdin).
30
31       fgets()  reads in at most one less than size characters from stream and
32       stores them into the buffer pointed to by s.  Reading  stops  after  an
33       EOF  or a newline.  If a newline is read, it is stored into the buffer.
34       A terminating null byte ('\0') is stored after the  last  character  in
35       the buffer.
36
37       ungetc()  pushes  c  back to stream, cast to unsigned char, where it is
38       available for subsequent read operations.  Pushed-back characters  will
39       be returned in reverse order; only one pushback is guaranteed.
40
41       Calls  to the functions described here can be mixed with each other and
42       with calls to other input functions from the stdio library for the same
43       input stream.
44
45       For nonlocking counterparts, see unlocked_stdio(3).
46

RETURN VALUE

48       fgetc(), getc(), and getchar() return the character read as an unsigned
49       char cast to an int or EOF on end of file or error.
50
51       fgets() returns s on success, and NULL on error or when end of file oc‐
52       curs while no characters have been read.
53
54       ungetc() returns c on success, or EOF on error.
55

ATTRIBUTES

57       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
58       tributes(7).
59
60       ┌────────────────────────────────────────────┬───────────────┬─────────┐
61Interface                                   Attribute     Value   
62       ├────────────────────────────────────────────┼───────────────┼─────────┤
63fgetc(), fgets(), getc(), getchar(),        │ Thread safety │ MT-Safe │
64ungetc()                                    │               │         │
65       └────────────────────────────────────────────┴───────────────┴─────────┘
66

STANDARDS

68       C11, POSIX.1-2008.
69

HISTORY

71       POSIX.1-2001, C89.
72

NOTES

74       It  is  not  advisable  to  mix calls to input functions from the stdio
75       library with  low-level  calls  to  read(2)  for  the  file  descriptor
76       associated  with  the  input  stream; the results will be undefined and
77       very probably not what you want.
78

SEE ALSO

80       read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
81       fseek(3),   getline(3),   gets(3),   getwchar(3),   puts(3),  scanf(3),
82       ungetwc(3), unlocked_stdio(3), feature_test_macros(7)
83
84
85
86Linux man-pages 6.05              2023-07-20                          fgetc(3)
Impressum