Line breaks and Linux carriage returns in Windows

Source: Internet
Author: User
The example text of line feed carriage return and Linux carriage return in Windows is as follows: fsad6546F5343646546345asfdsafsadfsda456749 + 8ASDFSAD: read the first line of Windows

The example text of line feed carriage return and Linux carriage return in Windows is as follows: fsad6546F5343646546345asfdsafsadfsda456749 + 8ASDFSAD: read the first line of Windows

The example text of line breaks and Linux carriage returns in Windows is as follows:

Fsad6546
F5343
646546345 asfdsa
Fsadfsda
456749 + 8
ASDFSAD

Read the first line

In Windows, the first line ends with \ r \ n, and the eight characters are followed by '\ r \ n'. when reading the C language fgetc, the ninth and tenth characters are both '\ n', And the next line of F is 11th characters

In Linux, there is no carriage return '\ R' and there is a line break. After reading 8 characters, it is' \ n', And the next line of F is the tenth character.

The following program reads text files and then outputs

(Be sure to get the length of a row first)

# Include
# Include
# Include

Int main ()
{

Char * str, c;
Str = (char *) malloc (1 );

Int k = 0, sum = 0;
FILE * pfile = fopen ("test.txt", "r ");

While (1)
{
Int I = 0;
Char d;
Int k = ftell (pfile );
Fseek (pfile, 8, SEEK_SET );
C = fgetc (pfile );
While (c! = '\ N ')
{

If (c =-1)
{
Fseek (pfile,-I, SEEK_CUR );
Goto first;
}
I ++;
C = fgetc (pfile );
K = ftell (pfile );
}
K = ftell (pfile );
D = fgetc (pfile );
K = ftell (pfile );
Fseek (pfile,-I-2, SEEK_CUR); // under Linux this should be changed to fseek (pfile,-i-1, SEEK_CUR );


First:
Free (str );
Str = (char *) malloc (I + 2 );
If (fgets (str, I + 2, pfile) = NULL)
{
Break;
}

Printf (str );

}
Fclose (pfile );
Return 0;
}

,

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.