同样的源代码,同样的编译器gcc

源代码:

main.c#include 
#include 
int main(int argc, char *args[]){        FILE *p1 = fopen("main.c","r");        char buf[1024] = {0};        while(!feof(p1))        {                fgets(buf,sizeof(buf),p1);                printf("%s",buf);        }        fclose(p1);        return 0;}// hello world

windows 运行:

D:\>gcc main.c & a.exe#include 
#include 
int main(int argc, char *args[]){        FILE *p1 = fopen("main.c","r");        char buf[1024] = {0};        while(!feof(p1))        {                fgets(buf,sizeof(buf),p1);                printf("%s",buf);        }        fclose(p1);        return 0;}// hello world

Linux 运行:

chunli@ubuntu:~/tmp$ gcc  main.c && ./a.out #include 
#include 
int main(int argc, char *args[]){        FILE *p1 = fopen("main.c","r");        char buf[1024] = {0};        while(!feof(p1))        {                fgets(buf,sizeof(buf),p1); printf("%s",buf);        }        fclose(p1);        return 0;}// hello world// hello world

可以看见,Linux比Windows会多输出一行