I understand your point, and thank you for the response. I think you missed my 
point, however, which is a method would be handy and less error prone. Case in 
point FLTK test code used atoi. Others might even use sscanf, and others may go 
out of their way and write a conversion from scratch. All overkill, if a method 
was provided.

just in case anyone is interested, following is a snippet on what the base 
value can be:

If the value of base is 0, the expected form of the subject sequence is that of 
a decimal constant, octal constant or hexadecimal constant, any of which may be 
preceded by a + or - sign. A decimal constant begins with a non-zero digit, and 
consists of a sequence of decimal digits. An octal constant consists of the 
prefix 0 optionally followed by a sequence of the digits 0 to 7 only. A 
hexadecimal constant consists of the prefix 0x or 0X followed by a sequence of 
the decimal digits and letters a (or A) to f (or F) with values 10 to 15 
respectively.


http://opengroup.org/onlinepubs/007908775/xsh/strtol.html

>
> > (atio will not work for hex values)
>
> The atoi function is actually pretty brain-dead, so if you do not know
> for certain that your numeric base is decimal, you should use strtol
> instead, since it can be passed a base.
> Also, if the given base is zero it makes a fairly convincing stab at
> guessing the correct base.
> I think the man pages actually say this, now I think of it...
>
> Attached example:
>
> #include <stdlib.h>
> #include <stdio.h>
>
> int main(void) {
>       char *txt =3D "0x0000AA55";
>       int v;
>       puts(txt);
>
>       v =3D atoi(txt);
>       printf("v is : %d (atoi is explicitly base 10)\n", v);
>
>       v =3D (int)strtol(txt, 0, 0);
>       printf("v is : %d or 0x%08X (strtol handles number base OK)\n",
> v, v);
>
>       return 0;
> }
> /* end of file */
>
>
> SELEX Galileo Ltd
> Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS=
> 14 3EL
> A company registered in England & Wales.  Company no. 02426132
> ********************************************************************
> This email and any attachments are confidential to the intended
> recipient and may also be privileged. If you are not the intended
> recipient please delete it from your system and notify the sender.
> You should not copy it or use it for any purpose nor disclose or
> distribute its contents to any other person.
> ********************************************************************
>

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to