fgets(3) Library Functions Manual fgets(3) NAME fgets - FILE get line-string LIBRARY Standard C library (libc, -lc) SYNOPSIS #include char *fgets(int size; char s[restrict size], int size, FILE *restrict stream); DESCRIPTION fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte ('\0') is stored after the last character in the buffer. RETURN VALUE fgets() returns s on success. When end of file occurs while no characters have been read, NULL is returned. On error, NULL is returned, and errno is set to indicate the error. ERRORS See fgetc(3). ATTRIBUTES For an explanation of the terms used in this section, see attributes(7). +--------------------------------------------+---------------+---------+ |Interface | Attribute | Value | +--------------------------------------------+---------------+---------+ |fgets () | Thread safety | MT-Safe | +--------------------------------------------+---------------+---------+ STANDARDS C11, POSIX.1-2008. HISTORY POSIX.1-2001, C89. SEE ALSO ferror(3), fgetc(3), fgetws(3), fopen(3), fread(3), getline(3), unlocked_stdio(3) Linux man-pages 6.19 2026-08-19 fgets(3)