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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fgets - get a string from a stream
13

SYNOPSIS

15       #include <stdio.h>
16
17       char *fgets(char *restrict s, int n, FILE *restrict stream);
18
19

DESCRIPTION

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

RETURN VALUE

34       Upon successful completion, fgets() shall return s. If the stream is at
35       end-of-file,  the end-of-file indicator for the stream shall be set and
36       fgets() shall return a null pointer.  If a read error occurs, the error
37       indicator  for  the  stream  shall  be set, fgets() shall return a null
38       pointer,  and shall set errno to indicate the error.
39

ERRORS

41       Refer to fgetc().
42
43       The following sections are informative.
44

EXAMPLES

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

APPLICATION USAGE

62       None.
63

RATIONALE

65       None.
66

FUTURE DIRECTIONS

68       None.
69

SEE ALSO

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