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       char *fgets(char *s, int size, FILE *stream);
14       int getc(FILE *stream);
15       int getchar(void);
16       char *gets(char *s);
17       int ungetc(int c, FILE *stream);
18

DESCRIPTION

20       fgetc() reads the next character from  stream  and  returns  it  as  an
21       unsigned char cast to an int, or EOF on end of file or error.
22
23       getc()  is equivalent to fgetc() except that it may be implemented as a
24       macro which evaluates stream more than once.
25
26       getchar() is equivalent to getc(stdin).
27
28       gets() reads a line from stdin into the buffer pointed to  by  s  until
29       either  a  terminating newline or EOF, which it replaces with '\0'.  No
30       check for buffer overrun is performed (see BUGS below).
31
32       fgets() reads in at most one less than size characters from stream  and
33       stores  them  into  the buffer pointed to by s.  Reading stops after an
34       EOF or a newline.  If a newline is read, it is stored into the  buffer.
35       A '\0' is stored after the last character in 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 non-locking 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       gets() and fgets() return s on success, and NULL on error or  when  end
52       of file occurs while no characters have been read.
53
54       ungetc() returns c on success, or EOF on error.
55

CONFORMING TO

57       C89, C99.  LSB deprecates gets().
58

BUGS

60       Never use gets().  Because it is impossible to tell without knowing the
61       data in advance how many  characters  gets()  will  read,  and  because
62       gets() will continue to store characters past the end of the buffer, it
63       is extremely dangerous to use.  It has  been  used  to  break  computer
64       security.  Use fgets() instead.
65
66       It  is  not  advisable  to  mix calls to input functions from the stdio
67       library with low-level calls to read() for the file descriptor  associā€
68       ated  with  the  input  stream;  the results will be undefined and very
69       probably not what you want.
70

SEE ALSO

72       read(2), write(2), ferror(3), fgetwc(3), fgetws(3), fopen(3), fread(3),
73       fseek(3),   getline(3),  getwchar(3),  puts(3),  scanf(3),  ungetwc(3),
74       unlocked_stdio(3)
75
76
77
78GNU                               1993-04-04                           GETS(3)
Impressum