The same source code, the same compiler GCC
Source:
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 runs:
D:\>GCC main.c & a.exe#include <stdio.h> #include <stdlib.h>int main (int argc, char *args[]) {FIL E *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 Run:
[Email protected]:~/tmp$ gcc main.c &&./a.out #include <stdio.h> #include <stdlib.h>int main (int arg C, Char *args[]) {FILE *P1 = fopen ("Main.c", "R"); Char buf[1024] = {0}; while (!feof (p1)) {fgets (buf,sizeof (BUF), p1);p rintf ("%s", buf); } fclose (p1); return 0;} Hello world//Hello World
As you can see, Linux outputs a single line more than Windows
This article is from the "Soul Bucket" blog, please be sure to keep this source http://990487026.blog.51cto.com/10133282/1786917
C read file differences between Windows and Linux