C read file differences between Windows and Linux

Source: Internet
Author: User
Tags c read file


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.