Re: passing array to isdigit()

From: Michael Mair (Michael.Mair_at_invalid.invalid)
Date: 02/14/05


Date: Mon, 14 Feb 2005 11:26:31 +0100


Dave Thompson wrote:
> On Wed, 09 Feb 2005 17:29:00 +0100, Michael Mair
> <Michael.Mair@invalid.invalid> wrote:
>
>
>>
>>Carramba wrote:
>>
>>>hi!
>>>
>>>I am trying to confirm if input is digit, so I thought it would by easy
>>>to do it with with isdigit() funktion,
>>>but how do I pass arrays to it if the imput is more then 1 sign?
>
>
> BTW in English we say character, or in general use mark or symbol but
> in computer programming symbol has a different meaning; or very
> formally glyph. 'Sign' means specifically plus + or minus/hyphen -.
>
>
>>You mean: more than one character.
>>There are several ways to go about this:
>>1) You have a string and pass it to a function which runs through the
>>whole string and checks every character (but not the string terminator)
>>with isdigit(). If you encounter non-digit, you return false.
>>2) You have an array of char and the number of potential digit
>>characters. Do as above and pass array and length but instead of
>>checking against the string terminator, run through all potential
>>digits using the length you got passed.
>
>
> Agree.
>
>
>>3) The strtol() function will convert a string into a long value.
>>Its interface provides the means to check whether the last digit
>>read was the last character before the string terminator.
>>Leading white spaces might be discarded -- just look it up.
>
> Optional leading whitespace and optional sign (in the sense above).
> Even the unsigned versions strtoul and strtoull accept a sign, even a
> minus/negative sign! And it fails to accept a string that is digits
> but whose numeric value overflows the return type.

Ack. You are right, of course.

>>4) Use sscanf() plus scanset restricted to the digits and get also
>>the number of read characters. If it equals the string length,
>>you know everything was a digit.
>
> Equals the length or (equivalently) identifies the end (terminator).

I am not sure what you want to say here -- do you agree with me
and just expand what I said?

> 5) Use strspn() and check if return equals length or identifies end.

I always forget strspn()/strcspn()... Thanks for the reminder :-)

Cheers
  Michael

-- 
E-Mail: Mine is a   gmx dot de   address.


Relevant Pages

  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • RfD: Escaped Strings version 4
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... as an escape character for the entry of characters that cannot be ... \b BS (backspace, ASCII 8) ...
    (comp.lang.forth)
  • Re: RfD: Escaped Strings
    ... the S" string can only contain printable characters, ... the S" string cannot contain the '"' character, ... \b BS (backspace, ASCII 8) ... \ ** escapes to characters much as C does. ...
    (comp.lang.forth)
  • Re: A note on computing thugs and coding bums
    ... code is valid for any character set that is legal in C (which is a ... characters in the required source character set ... A String, in C Sharp or Java, can be redefined. ... allow programmers to handle some other data format, ...
    (comp.programming)
  • Re: input & output in assembly
    ... [As you've not specified OS or assembler, ... using individual character I/O and handling the rest yourself in your ... it finds in that string, ... ENTER key is pressed (maximum buffer size: ...
    (comp.lang.asm.x86)