同样的源代码,同样的编译器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会多输出一行
转载于:https://blog.51cto.com/990487026/1786917