同樣的源代碼,同樣的編譯器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 worldwindows 運行: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 worldLinux 運行: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