Re: GtkEntry only for numbers



> On Wed, Jan 31, 2001 at 03:30:57PM -0200, Flavio Ribeiro wrote:
> > b. The easy way: run strtof() on the string and see if it returns 0. If it
> > does, the user either entered '0' or entered something illegal. Read
> > strtof's man page for more ideas.
>
>         % man strtof
>         No manual entry for strtof
>         % uname -sr
>         FreeBSD 3.4-RELEASE
>
> On the other hand:
>
>         % man strtod
>

I'm sorry, I actually meant strtod(). There's no strtof. The question's author
prompted for a float and that got me going without thinking, specially since
atof() actually returns a double.

>
> Note also that if you hand "strtod()" the string "6.02e23qqqq", it will
> return 6.02e+23, not 0.0 - i.e., it doesn't treat extra characters at
> the end of the string as an error (presumably because the intent is that
> it can be used to carve numeric tokens out of a string).
>

Yes, but it will return 0 if you present the string "qqqqq6.02e23" or even
"qqqqqqqqq" and you'll have to be prepared for such an input [as you comment
later on]

Flavio





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]