1gets(3C) Standard C Library Functions gets(3C)
2
3
4
6 gets, fgets - get a string from a stream
7
9 #include <stdio.h>
10
11 char *gets(char *s);
12
13
14 char *fgets(char *s, int n, FILE *stream);
15
16
18 The gets() function reads bytes from the standard input stream (see
19 Intro(3)), stdin, into the array pointed to by s, until a newline char‐
20 acter is read or an end-of-file condition is encountered. The newline
21 character is discarded and the string is terminated with a null byte.
22
23
24 If the length of an input line exceeds the size of s, indeterminate
25 behavior may result. For this reason, it is strongly recommended that
26 gets() be avoided in favor of fgets().
27
28
29 The fgets() function reads bytes from the stream into the array pointed
30 to by s, until n−1 bytes are read, or a newline character is read and
31 transferred to s, or an end-of-file condition is encountered. The
32 string is then terminated with a null byte.
33
34
35 The fgets() and gets() functions may mark the st_atime field of the
36 file associated with stream for update. The st_atime field will be
37 marked for update by the first successful execution of fgetc(3C),
38 fgets(), fread(3C), fscanf(3C), getc(3C), getchar(3C), gets(), or
39 scanf(3C) using stream that returns data not supplied by a prior call
40 to ungetc(3C) or ungetwc(3C).
41
43 If end-of-file is encountered and no bytes have been read, no bytes are
44 transferred to s and a null pointer is returned. For standard-conform‐
45 ing (see standards(5)) applications, if the end-of-file indicator for
46 the stream is set, no bytes are transferred to s and a null pointer is
47 returned whether or not the stream is at end-of-file. If a read error
48 occurs, such as trying to use these functions on a file that has not
49 been opened for reading, a null pointer is returned and the error indi‐
50 cator for the stream is set. If end-of-file is encountered, the EOF
51 indicator for the stream is set. Otherwise s is returned.
52
54 Refer to fgetc(3C).
55
57 See attributes(5) for descriptions of the following attributes:
58
59
60
61
62 ┌─────────────────────────────┬─────────────────────────────┐
63 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
64 ├─────────────────────────────┼─────────────────────────────┤
65 │Interface Stability │Standard │
66 ├─────────────────────────────┼─────────────────────────────┤
67 │MT-Level │MT-Safe │
68 └─────────────────────────────┴─────────────────────────────┘
69
71 lseek(2), read(2), ferror(3C), fgetc(3C), fgetwc(3C), fopen(3C),
72 fread(3C), getchar(3C), scanf(3C), stdio(3C), ungetc(3C), ungetwc(3C),
73 attributes(5), standards(5)
74
75
76
77SunOS 5.11 15 Oct 2003 gets(3C)