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

  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)
  • Re: Mod 43 Check Digit calculator
    ... miscalculation of the check digit. ... > response to you) should return the check character itself rather than> the ... Here is that formula with the absolute reference problem> that ... > space in the encoding string at the 39th position. ...
    (microsoft.public.excel.programming)
  • 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)