diff --git a/c-programming/io/freadln.c b/c-programming/io/freadln.c index 80888da..d4672be 100644 --- a/c-programming/io/freadln.c +++ b/c-programming/io/freadln.c @@ -10,7 +10,7 @@ * TODO: Figure out potential problems * TODO: Add 'flushing' of STDIN (while there are characters, read them) before * the input reading loop to avoid input queues - * FIXME: Handle EOF in a special way to indicate EOF + * [optional] TODO: Handle EOF in a special way to indicate EOF */ #include "freadln.h" @@ -93,11 +93,14 @@ int main(void) { exit(EXIT_FAILURE); } f = new_f; - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 4; i++) { size_t line_length; if (freadln(f, &line, &line_length) != freadln_OK) { perror("freadln"); exit(EXIT_FAILURE); + } else if (feof(f)) { + printf("File: EOF, breaking the loop\n"); + break; } printf("File, line #%d: '%s' (%zu characters)\n", i + 1, line, line_length);