[Gambas-user] Convert string to integer with arbitrary base

tobias tobiasboe1 at ...20...
Fri Jan 20 23:17:45 CET 2012


oops,
make this comma in the for loop head a semicolon...

> /*
>    * STR:          I string containing symbols
>    * AL:           I alphabet to put symbols in order
>    * RET:          O result in integer format
>    * return value: O number of symbols put into the integer
>    */
> char stoi_al(char *str, char *al, unsigned int *ret)
> {
>       int i;
>       unsigned int n = 0, base, c = 0;
>       char *ind;
>
>       base = strlen(al);
>       for (i = 0, str[i]; i++)
>       {
>           if (!(ind = strchr(al, str[i]))) break;
>           n = n * base + ind - al;
>           c++;
>       }
>       *ret = n;
>       return c;
> }
>





More information about the User mailing list