mirror of
https://gitlab.com/80486DX2-66/gists
synced 2024-12-27 14:50:23 +05:30
freadln.c: improve the test, make last TODO optional
This commit is contained in:
parent
1a69cfa4ad
commit
d7be00df1f
@ -10,7 +10,7 @@
|
|||||||
* TODO: Figure out potential problems
|
* TODO: Figure out potential problems
|
||||||
* TODO: Add 'flushing' of STDIN (while there are characters, read them) before
|
* TODO: Add 'flushing' of STDIN (while there are characters, read them) before
|
||||||
* the input reading loop to avoid input queues
|
* 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"
|
#include "freadln.h"
|
||||||
@ -93,11 +93,14 @@ int main(void) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
f = new_f;
|
f = new_f;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
size_t line_length;
|
size_t line_length;
|
||||||
if (freadln(f, &line, &line_length) != freadln_OK) {
|
if (freadln(f, &line, &line_length) != freadln_OK) {
|
||||||
perror("freadln");
|
perror("freadln");
|
||||||
exit(EXIT_FAILURE);
|
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,
|
printf("File, line #%d: '%s' (%zu characters)\n", i + 1, line,
|
||||||
line_length);
|
line_length);
|
||||||
|
Loading…
Reference in New Issue
Block a user