FILE * Pfilein;
Pfilein=fopen ("XXX.txt", "RT");
int __cdecl fgetc (REG1 FILE *stream);
char * __cdecl fgets (_tschar *string,int count,file *str);
and Fputc,fgets, fscanf,fprintf.
1. The above are all provided by C language File operation method, which has binary mode: B and text mode T.
Difference:
Binary mode, in fact, the hard drive inside the things moved to the memory, do not handle. Read the words (now default to ASCII characters, followed by a discussion of the differences between the different encodings)
For enter, the two ASCII characters are generated in memory (because they exist in the hard disk). \ r \ n
Why use two characters to represent an action, this is from the previous English typing machine operating mode is (first step) to the type of car first move to the side of the typing (carriage), (second step)
And then move down one line (line-breaking), which is split in half, so it's roughly considered a legacy of history.
Text mode, because we say the text, is human readable, then there is no need to use two steps to represent an action, the use of/n is finished. But the two models are causing
Confused, when I read in binary mode, saved in text mode will be a more than a \ r, when you open with EditPlus, you will find the following:
0D 0A before multiple 0D, Notepad ignores redundant 0D;
Similarly, open with text mode, save with binary, and then open with a text program, there is less than A/R, as follows:
And for such a malformed thing, Windows itself is not aware of Notepad:
And EditPlus after all is a professional tool, so it is possible, not on the map ...
2. The previous coding method is the system default encoding, ANSI it is a mixture, for English is ASCII, for Chinese characters is GB2312, our C language provides the above several ways to support this encoding only,
For Unicode,utf-8 and so on will appear garbled:
Ansi
Utf-8
Unicode
3.gets
The above is for reference only, may have a lot of deficiencies and errors, welcome to point out.