Reference:C Functions and Keywords/ANSI-ISO Standard C/fgets()

From CoderGuide

Jump to: navigation, search

Language Cross Reference

 C++ Java Perl PHP Python


#include <stdio.h>
char *fgets(char *s, size_t size, FILE *stream);

fgets reads in size_t size bytes from stream and stores them into s. It will continue to read from the stream until a newline or EOF is encountered. If a newline is read, then it will be included as part of the string. This is unlike the gets(), however, the benefit is protection against buffer overruns (reading in more bytes that your string was allocated for).

The return value is NULL on failure, otherwise it returns a pointer to s

See also

gets(), getchar(), getc(), ungetc(), fopen(), fread(), fputs(), putc(), puts(), putchar(), Guides:C/C Crash Course/Standard Input (stdin)

Personal tools