Re: Token Parser
- From: "T.M. Sommers" <tms@xxxxxx>
- Date: Tue, 26 Jul 2005 14:41:32 GMT
CBFalconer wrote:
"T.M. Sommers" wrote:CBFalconer wrote:"T.M. Sommers" wrote:
Use this instead:
while ( (c = getchar()) != EOF && isdigit(c) ) {
This was an error in the code I posted earlier. You don't want to isdigit(EOF).
This is an error. He wants to find the non-digit operators also. There is no problem passing EOF to isdigit, it will reply 'no'.
You are quite right. I was under the impression that the argument had to be an unsigned char, but the standard also allows EOF.
The error part was that you changed the logic so that it could no longer return the various operators, skipblanks, etc. The other is unnecessary, rather than an error.
I cut and pasted from my own code, which used a different variable for the input character ('c' vice 'next_token'), which was an error, but other than that I don't see any error in the above line (except that one should perhaps guarantee that c can be cast to unsigned char). The loop controlled by the while is over digits after the first, and will stop when and only when c is not a digit. The only thing the EOF test changes is that isdigit() will not be called for EOF, which, as you pointed out, is unnecessary.
-- Thomas M. Sommers -- tms@xxxxxx -- AB2SB
.
- References:
- Token Parser
- From: Simon Morgan
- Re: Token Parser
- From: Simon Morgan
- Re: Token Parser
- From: T.M. Sommers
- Re: Token Parser
- From: CBFalconer
- Re: Token Parser
- From: T.M. Sommers
- Re: Token Parser
- From: CBFalconer
- Token Parser
- Prev by Date: Re: question about random generator
- Next by Date: Re: Why??
- Previous by thread: Re: Token Parser
- Next by thread: How to deal with Tree with several branchs?
- Index(es):
Relevant Pages
|