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;
}
,