##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# fgets

From cppreference.com
< c‎ | io

Defined in header `<stdio.h>` |  |

char *fgets( char *str, int count, FILE *stream ); |  | (until C99)
char *fgets( char *restrict str, int count, FILE *restrict stream ); |  | (since C99)

Reads at most count - 1 characters from the given file stream and stores them in `str`. The produced character string is always NULL-terminated. Parsing stops if end-of-file occurs or a newline character is found, in which case `str` will contain that newline character.

### [edit] Parameters

str | - | string to read the characters to
count | - | the length of `str`
stream | - | file stream to read the data from

### [edit] Return value

`str` on success, NULL on failure.

If the failure has been caused by end of file condition, additionally sets the eof indicator (see feof()) on `stream`. If the failure has been caused by some other error, sets the error indicator (see ferror()) on `stream`.

### [edit] See also

scanf fscanf sscanf | reads formatted input from stdin, a file stream or a buffer (function) [edit]
gets | reads a character string from `stdin` (function) [edit]
fputs | writes a character string to a file stream (function) [edit]
C++ documentation for fgets

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/io/fgets&oldid=66531"