Re: passing array to isdigit()
From: Michael Mair (Michael.Mair_at_invalid.invalid)
Date: 02/14/05
- Next message: jjf_at_bcs.org.uk: "Re: C portability is a myth"
- Previous message: BRG: "Re: What is a sequence point?"
- In reply to: Dave Thompson: "Re: passing array to isdigit()"
- Next in thread: CBFalconer: "Re: passing array to isdigit()"
- Reply: CBFalconer: "Re: passing array to isdigit()"
- Reply: Dave Thompson: "Re: passing array to isdigit()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: jjf_at_bcs.org.uk: "Re: C portability is a myth"
- Previous message: BRG: "Re: What is a sequence point?"
- In reply to: Dave Thompson: "Re: passing array to isdigit()"
- Next in thread: CBFalconer: "Re: passing array to isdigit()"
- Reply: CBFalconer: "Re: passing array to isdigit()"
- Reply: Dave Thompson: "Re: passing array to isdigit()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|