| Main index | Section 3 | 日本語 | Options |
#include <stdio.h>
The text to which the returned pointer points may be modified, provided that no changes are made beyond the returned size. These changes are lost as soon as the pointer becomes invalid.
| [EBADF] | |
| The argument stream is not a stream open for reading. | |
| [ENOMEM] | |
| The internal line buffer could not be expanded due to lack of available memory, or because it would need to expand beyond INT_MAX in size. | |
The fgetln() function may also fail and set errno for any of the errors specified for the routines fflush(3), malloc(3), read(2), stat(2), or realloc(3).
char *buf, *lbuf; size_t len;lbuf = NULL; while ((buf = fgetln(fp, &len)) != NULL) { if (buf[len - 1] == '\n') buf[len - 1] = '\0'; else { /* EOF without EOL, copy and add the NUL */ if ((lbuf = malloc(len + 1)) == NULL) err(1, NULL); memcpy(lbuf, buf, len); lbuf[len] = '\0'; buf = lbuf; } printf("%s\n", buf); } free(lbuf); if (ferror(fp)) err(1, "fgetln");
| FGETLN (3) | June 11, 2020 |
| Main index | Section 3 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
