stdin
is buffered which could be the reason why some of the lines from the text file are missed out. You could possibly make stdin
unbuffered using setvbuf(fd, NULL, _IONBF, 0)
or equivalent before fgets
call in your C program and address this issue.
Alternatively, you can read character by character following the suit of line
utility. Maybe something on the lines of :
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
char c;
while(read(STDIN_FILENO , &c, 1) > 0 && c != '\n')
putchar(c);
return EXIT_SUCCESS;
}
Hope this helps!