Jump to content

C++ Programming/Code/Standard C Library/Functions/fgets

From Wikibooks, open books for an open world

fgets

[edit | edit source]
Syntax
#include <cstdio>
char *fgets( char *str, int num, FILE *stream );

The function fgets() reads up to num - 1 characters from the given file stream and dumps them into str. The string that fgets() produces is always null-terminated. fgets() will stop when it reaches the end of a line, in which case str will contain that newline character. Otherwise, fgets() will stop when it reaches num - 1 characters or encounters the EOF character. fgets() returns str on success, and NULL on an error.

Related topics
fputs - fscanf - gets - scanf