view test/bug55.d @ 133:44a95ac7368a trunk

[svn r137] Many fixes towards tango.io.Console working, but not quite there yet... In particular, assertions has been fixed to include file/line info, and much more!
author lindquist
date Mon, 14 Jan 2008 05:11:54 +0100
parents 70d6113eeb8c
children d9d5d59873d8
line wrap: on
line source

module bug55;

int atoi(char[] s) {
    int i, fac=1;
    bool neg = (s.length) && (s[0] == '-');
    char[] a = neg ? s[1..$] : s;
    foreach_reverse(c; a) {
        i += (c-'0') * fac;
        fac *= 10;
    }
    return !neg ? i : -i;
}

void main()
{
    printf("64213 = %d\n", atoi("64213"));
    printf("-64213 = %d\n", atoi("-64213"));
    assert(atoi("64213") == 64213);
    assert(atoi("-64213") == -64213);
}