1GETS(3) Linux Programmer's Manual GETS(3)
2
3
4
6 fgetc, fgets, getc, getchar, gets, ungetc - input of characters and
7 strings
8
10 #include <stdio.h>
11
12 int fgetc(FILE *stream);
13
14 char *fgets(char *s, int size, FILE *stream);
15
16 int getc(FILE *stream);
17
18 int getchar(void);
19
20 char *gets(char *s);
21
22 int ungetc(int c, FILE *stream);
23
25 fgetc() reads the next character from stream and returns it as an
26 unsigned char cast to an int, or EOF on end of file or error.
27
28 getc() is equivalent to fgetc() except that it may be implemented as a
29 macro which evaluates stream more than once.
30
31 getchar() is equivalent to getc(stdin).
32
33 gets() reads a line from stdin into the buffer pointed to by s until
34 either a terminating newline or EOF, which it replaces with '\0'. No
35 check for buffer overrun is performed (see BUGS below).
36
37 fgets() reads in at most one less than size characters from stream and
38 stores them into the buffer pointed to by s. Reading stops after an
39 EOF or a newline. If a newline is read, it is stored into the buffer.
40 A '\0' is stored after the last character in the buffer.
41
42 ungetc() pushes c back to stream, cast to unsigned char, where it is
43 available for subsequent read operations. Pushed-back characters will
44 be returned in reverse order; only one pushback is guaranteed.
45
46 Calls to the functions described here can be mixed with each other and
47 with calls to other input functions from the stdio library for the same
48 input stream.
49
50 For non-locking counterparts, see unlocked_stdio(3).
51
53 fgetc(), getc() and getchar() return the character read as an unsigned
54 char cast to an int or EOF on end of file or error.
55
56 gets() and fgets() return s on success, and NULL on error or when end
57 of file occurs while no characters have been read.
58
59 ungetc() returns c on success, or EOF on error.
60
62 C89, C99, POSIX.1-2001. LSB deprecates gets(). POSIX.1-2008 removes
63 the specification of gets().
64
66 Never use gets(). Because it is impossible to tell without knowing the
67 data in advance how many characters gets() will read, and because
68 gets() will continue to store characters past the end of the buffer, it
69 is extremely dangerous to use. It has been used to break computer
70 security. Use fgets() instead.
71
72 It is not advisable to mix calls to input functions from the stdio
73 library with low-level calls to read(2) for the file descriptor associā
74 ated with the input stream; the results will be undefined and very
75 probably not what you want.
76
78 read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
79 fseek(3), getline(3), getwchar(3), puts(3), scanf(3), ungetwc(3),
80 unlocked_stdio(3)
81
83 This page is part of release 3.22 of the Linux man-pages project. A
84 description of the project, and information about reporting bugs, can
85 be found at http://www.kernel.org/doc/man-pages/.
86
87
88
89GNU 2008-08-06 GETS(3)