I'm a beginner of C. When I use this while loop to print the contains of a file. The last line will print twice on Linux. It should not get into while loop when reach the end of file. It has no problem on windows.
#include <stdio.h>
#include <unistd.h>
int main()
{
char string[400];
FILE *file_para;
// Open the file
if ((file_para = fopen("Test.txt", "r")) == NULL)
{
printf("cannot open file\n");
getchar();
return 0;
}
while (!feof(file_para))
{
fgets(string, 400, file_para);
printf("**** %s", string);
}
fclose(file_para);
getchar();
return 0;
}