I am trying to print the log file information to the terminal and I am using the below code to do so. But here I am able to print to the terminal only after log file generation is complete and with this getting some delay in the terminal.
But I want to log to the terminal in the real time. As data to the log file is getting printed, It should reflect to terminal as well in real time. Please let me know how can I modify the below code.
Suggestions are appreciated.
Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
FILE * xFile;
char buffer [100];
xFile = fopen ( path to file, "r");
if (xFile == NULL)
{
perror ("Error opening log file to print to output stream");
}
else
{
while ( ! feof (xFile) )
{
if ( fgets (buffer , 100 , xFile) == NULL ) break;
fputs (buffer , stdout);
}
fclose (xFile);
}