1GETS(3)                    Linux Programmer's Manual                   GETS(3)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

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 a null byte
35       ('\0').  No 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  terminating  null  byte ('\0') is stored after the last character in
41       the buffer.
42
43       ungetc() pushes c back to stream, cast to unsigned char,  where  it  is
44       available  for subsequent read operations.  Pushed-back characters will
45       be returned in reverse order; only one pushback is guaranteed.
46
47       Calls to the functions described here can be mixed with each other  and
48       with calls to other input functions from the stdio library for the same
49       input stream.
50
51       For nonlocking counterparts, see unlocked_stdio(3).
52

RETURN VALUE

54       fgetc(), getc() and getchar() return the character read as an  unsigned
55       char cast to an int or EOF on end of file or error.
56
57       gets()  and  fgets() return s on success, and NULL on error or when end
58       of file occurs while no characters have been read.
59
60       ungetc() returns c on success, or EOF on error.
61

CONFORMING TO

63       C89, C99, POSIX.1-2001.
64
65       LSB deprecates gets().  POSIX.1-2008 marks gets() obsolescent.  ISO C11
66       removes the specification of gets() from the C language, and since ver‐
67       sion 2.16, glibc header files don't expose the function declaration  if
68       the _ISOC11_SOURCE feature test macro is defined.
69

BUGS

71       Never use gets().  Because it is impossible to tell without knowing the
72       data in advance how many  characters  gets()  will  read,  and  because
73       gets() will continue to store characters past the end of the buffer, it
74       is extremely dangerous to use.  It has  been  used  to  break  computer
75       security.  Use fgets() instead.
76
77       It  is  not  advisable  to  mix calls to input functions from the stdio
78       library with low-level calls to read(2) for the file descriptor associ‐
79       ated  with  the  input  stream;  the results will be undefined and very
80       probably not what you want.
81

SEE ALSO

83       read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
84       fseek(3),   getline(3),  getwchar(3),  puts(3),  scanf(3),  ungetwc(3),
85       unlocked_stdio(3), feature_test_macros(7)
86

COLOPHON

88       This page is part of release 3.53 of the Linux  man-pages  project.   A
89       description  of  the project, and information about reporting bugs, can
90       be found at http://www.kernel.org/doc/man-pages/.
91
92
93
94GNU                               2012-01-18                           GETS(3)
Impressum