1FGETS(P)                   POSIX Programmer's Manual                  FGETS(P)
2
3
4

NAME

6       fgets - get a string from a stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *fgets(char *restrict s, int n, FILE *restrict stream);
12
13

DESCRIPTION

15       The  fgets()  function  shall  read  bytes  from  stream into the array
16       pointed to by s, until n-1 bytes are read, or a <newline> is  read  and
17       transferred  to  s,  or  an  end-of-file  condition is encountered. The
18       string is then terminated with a null byte.
19
20       The fgets() function may mark the st_atime field of the file associated
21       with  stream  for update. The st_atime field shall be marked for update
22       by the  first  successful  execution  of  fgetc(),  fgets(),  fgetwc(),
23       fgetws(),  fread(),  fscanf(),  getc(),  getchar(),  gets(), or scanf()
24       using stream that returns data not supplied by a prior call to ungetc()
25       or ungetwc().
26

RETURN VALUE

28       Upon successful completion, fgets() shall return s. If the stream is at
29       end-of-file, the end-of-file indicator for the stream shall be set  and
30       fgets() shall return a null pointer.  If a read error occurs, the error
31       indicator for the stream shall be set,  fgets()  shall  return  a  null
32       pointer,    and shall set errno to indicate the error.
33

ERRORS

35       Refer to fgetc() .
36
37       The following sections are informative.
38

EXAMPLES

40   Reading Input
41       The  following  example  uses  fgets()  to  read  each  line  of input.
42       {LINE_MAX}, which defines the  maximum  size  of  the  input  line,  is
43       defined in the <limits.h> header.
44
45
46              #include <stdio.h>
47              ...
48              char line[LINE_MAX];
49              ...
50              while (fgets(line, LINE_MAX, fp) != NULL) {
51              ...
52              }
53              ...
54

APPLICATION USAGE

56       None.
57

RATIONALE

59       None.
60

FUTURE DIRECTIONS

62       None.
63

SEE ALSO

65       fopen()   ,   fread()  ,  gets()  ,  the  Base  Definitions  volume  of
66       IEEE Std 1003.1-2001, <stdio.h>
67
69       Portions of this text are reprinted and reproduced in  electronic  form
70       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
71       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
72       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
73       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
74       event of any discrepancy between this version and the original IEEE and
75       The Open Group Standard, the original IEEE and The Open Group  Standard
76       is  the  referee document. The original Standard can be obtained online
77       at http://www.opengroup.org/unix/online.html .
78
79
80
81IEEE/The Open Group                  2003                             FGETS(P)
Impressum