Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006


Fgetc, and other EOF

In another message in response to my article, some of my friends and I had some discussions on getc. Feeling landlord could not understand
I mean, I summed up my personal opinion, written there. I am not an expert, but I have the best.
Anyone who switch to the stickers, please be sure to write my name put in a prominent position. 8)


Gcc2/x86 agreement for the compiler :
Therefore, char, unsigned char is 8 bits, for 32 int

Please refer http://www.lslnet.com/linux/#forum/23/20031223/229236.html


(1) bytes of reading

In normal circumstances, unsigned char getc to read the paper flow, the expansion of an integer and return
Back. In other words, getc take a byte stream from the paper, and add 24%, less than 256 as a rounded,
Then returned.

Int c;
While ((c = fgetc (rfp))> -1) -1 is the 4003rd EOF
Fputc (c, wfp);

Although the c above fputc integer, but in fputc to flow into the document before, a strip of high-integer 24
Away, fgetc, putc complex document can be achieved with the system. So far, the definition of c
Char is still possible, but we will see below, is defined as int c is the correct end-of documents.

(2) to determine the paper concluded.

Most people think that a document EOF, which is used to represent the end of the document. But this view is wrong, in the text
Data contained in the documents and no documents at the end. Getc for, if not to read from the document.
Will return an integer 1, which is called the EOF. EOF is nothing more than a return of two cases, the first document
After reading; Second, document retrieval mistake, because it is time not go on.

Please note that read : normal circumstances, the return of integer less than 256, 0x0~0xFF. And the return can not reproduce
Is 0xFFFFFFFF. However, if you put 0xFFFFFFFF fputc got to write papers, 24 were high shielding, will be included in the
Is 0xFF. Please note that the 4003rd lixforalpha

(3) We will 0xFF confusion?

Not, the prerequisite is to receive the return value is defined as int c according to a prototype.

If a reading of the characters will 0xFF,

Int c;
C = fgetc (rfp); 4003rd c = 0x000000FF;
If (c> -1) 4003rd course ranging from -1 is 0xFFFFFFFF
Fputc (wfp); 4003rd Oh, OXFF duplicating success.

Character 0xFF, EOF is not its own.

(4) The definition of char c

0xFF assumption is for a reading of the characters

Char c;
C = fgetc (rfp); 4003rd fgetc (rfp), the value of 0x000000FF secretly reduced byte, c = 0xFF
If (c> -1) 4003rd character and integer? C was taken Symbol (signed) for the expansion of 0xFFFFFFFF, oh, uh,
Conditions set up complex documents from the earlier system.

While ((c=fgetc (rfp)) !=EOF), the criterion established, the document reproduction end! When the plane accident.

(5) c is defined as unsigned char;

When he read the end of the document and return EOF is -1.

Unsigned char c;
C = fgetc (rfp); 4003rd fgetc (rfp), the value of the EOF, -1, 0xFFFFFFFF, downgraded byte c=0xFF
If (c!= -1) was extended to 4003rd c 0x000000FF never return equivalent to 0xFFFFFFFF

So, although the system can correct complex 0xFF, it is unable to judge whether paper concluded. In fact, for uchar c,
C> 1 is never established, a high-quality compiler, such as gcc compiler in this point.

(6) the need for feof?
FILE *fp;
Fp point to a very complex data structure, the structure is a symbol feof to determine whether the end.
If fgetc read the document, the final one just read out the characters, fp signs will not break the EOF, then
Feof use judgment, will be concluded before the end of paper.

Fgetc return -1, we are still not convinced that the document has come to an end, it might be wrong to read! Then we
Feof and ferror needs.

Fgetc, and other EOF

Thank you, hematemesis dedication
Very good, finally came to understand!
Even lower on the skill of a really bad!
All in all, the book put some really sloppy : - (

Fgetc, and other EOF

Win_hate ah, here in the morning to see you on the law articles, written in great detail, the essence of originality, you do not have a view!

Ha ha

Fgetc, and other EOF

-->

Thank you, boss!

Fgetc, and other EOF

Win_hate's because of the brothers to pursue the study of the spirit in the end, the Forum has several such people, we must be able to lead the initiative

Fgetc, and other EOF

Laughter. Chances are the top!
After more fat article!

Fgetc, and other EOF

Lenovo contribution and the spirit we have witnessed here in the future when you are prepared to allow the successor!

Keep up the good work!

Enhance one another. . . .

Fgetc, and other EOF

-->
Thank you encourage!
Ashamed of yourselves, Boss!

Fgetc, and other EOF

Aggregate OK, reversed his role as guest by making his suggestions : try not to use substitute 1 EOF. EOF is with the system, not some of the EOF 1.

Fgetc, and other EOF

Presented the honor to be given a detailed explanation of the hardship win_hate, flw, dadaball, aero, blue keyboard so many friends

Em02 : : : : em02 em02 [url=http://lixforalpha.533.net/i_want_to_do/wmjd.pdf] perfect answer : : : : em02



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com