/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>

int toint(const char *s)
{
    int res;
    sscanf(s, "%d", &res);
    return res;
}

int tointx(const char *s)
{
    int res, i;
    res = 0;
    for(i = 0; i < strlen(s); i++)
    {
        res = 10 * res + (s[i] - '0');
    }
    return res;
}

int tointxx(const char *s)
{
    int res, i;
    res = 0;
    for(i = 0; i < strlen(s); i++)
    {
        res = 10 * res + (s[i] - 48);
    }
    return res;
}

void test(const char *s)
{
    printf("\"%s\" : %d\n", s, toint(s));
    printf("\"%s\" : %d\n", s, tointx(s));
    printf("\"%s\" : %d\n", s, tointxx(s));
}

int main(int argc, char *argv[])
{
    test("1");
    test("12");
    test("123");
    return 0;
}
