| 1 | .\" @(#)gets.3 6.1 (Berkeley) %G% |
| 2 | .\" |
| 3 | .TH GETS 3S "" |
| 4 | .AT 3 |
| 5 | .SH NAME |
| 6 | gets, fgets \- get a string from a stream |
| 7 | .SH SYNOPSIS |
| 8 | .B #include <stdio.h> |
| 9 | .PP |
| 10 | .B char *gets(s) |
| 11 | .br |
| 12 | .B char *s; |
| 13 | .PP |
| 14 | .B char *fgets(s, n, stream) |
| 15 | .br |
| 16 | .B char *s; |
| 17 | .br |
| 18 | .SM |
| 19 | .B FILE |
| 20 | .B *stream; |
| 21 | .SH DESCRIPTION |
| 22 | .I Gets |
| 23 | reads a string into |
| 24 | .I s |
| 25 | from the standard input stream |
| 26 | .BR stdin . |
| 27 | The string is terminated by a newline |
| 28 | character, which is replaced in |
| 29 | .I s |
| 30 | by a null character. |
| 31 | .I Gets |
| 32 | returns its argument. |
| 33 | .PP |
| 34 | .I Fgets |
| 35 | reads |
| 36 | .IR n \-1 |
| 37 | characters, or up through a newline |
| 38 | character, whichever comes first, |
| 39 | from the |
| 40 | .I stream |
| 41 | into the string |
| 42 | .IR s . |
| 43 | The last character read into |
| 44 | .I s |
| 45 | is followed by a null character. |
| 46 | .I Fgets |
| 47 | returns its first argument. |
| 48 | .SH "SEE ALSO" |
| 49 | puts(3S), |
| 50 | getc(3S), |
| 51 | scanf(3S), |
| 52 | fread(3S), |
| 53 | ferror(3S) |
| 54 | .SH DIAGNOSTICS |
| 55 | .I Gets |
| 56 | and |
| 57 | .I fgets |
| 58 | return the constant pointer |
| 59 | .SM |
| 60 | .B NULL |
| 61 | upon end of file or error. |
| 62 | .SH BUGS |
| 63 | .I Gets |
| 64 | deletes a newline, |
| 65 | .I fgets |
| 66 | keeps it, |
| 67 | all in the name of backward compatibility. |