Eric Sosman <> writes:
> luserXtrog wrote:
>>
>> Why not use isdigit for that?
>> And a little loop across the string?
>>
>> #include <stdio.h>
>>
>> int main(void) {
>> char *s="12345a";
>>
>> do if (!isdigit(*s)) {
>
> Perl? Ada? PL/X? Whatever the language is, it's one I don't
> speak fluently.
Eric, you're about to kick yourself. It's C. Try compiling it.
I hate the code layout, though. Rather than this:
do if (condition1) {
/* ... */
} while (condition2);
I'd write:
do {
if (condition1) {
/* ... */
}
} while (condition2);
I rarely use or even see do-while loops; combining one with an if
statement that way is understandably confusing.
> If this were C, though, you'd want `isdigit( (unsigned char)*s )'
> for reasons that have been explained many times before.
>
>> printf("%c is not a digit\n", *s);
>> } while(*++s);
>>
>> return 0;
>> }
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"