同样的源代码,同样的编译器gcc
源代码:
main.c #include <stdio.h> #include <stdlib.h> 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 <stdio.h> #include <stdlib.h> 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 <stdio.h> #include <stdlib.h> 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会多输出一行
本文出自 “魂斗罗” 博客,请务必保留此出处http://990487026.blog.51cto.com/10133282/1786917
原文地址:http://990487026.blog.51cto.com/10133282/1786917