tr-demoscene

the scene => coding => console => Konuyu başlatan: skate - 29.05.2007 14:26:22

Başlık: GP2X Standart Library Eksikleri
Gönderen: skate - 29.05.2007 14:26:22
Gnostic ya da diğer daha önce GP2X coding ile uğraşmış arkadaşlar, GP2X'in standart C librarylerinde bazı eksikler gözüme çarptı. Örneğin atoi varken itoa yok v.s. sprintf ile işi çözdüm ancak yine de "itoa"nın niye olmadığı ve daha önemlisi başka hangi eksiklerin olduğu kafamı kurcaladı. Böyle bir liste var mıdır? Incompitibility ya da todo list tarzı birşeyler?
Başlık: GP2X Standart Library Eksikleri
Gönderen: GnoStiC - 29.05.2007 15:00:55
itoa standart olarak c/c++ lib'lerinde yok diye biliyorum ben? yanlis olabilir tabi bu bilgim..

itoa ihtiyacim 1 kez oldu (o da psp icin), onda da snprintf kullandim..

Kod: [Seç]
//code: gfoot
char *itoa (int num, char *str, int base)
{
    char *pos = str;
    int digit_value;

    if (num < 0) {
        *pos++ = '-';
        num = -num;
    }

    digit_value = 1;
    while (digit_value*base <= num) digit_value *= base;
    while (digit_value > 0) {
        int digit = num / digit_value;
        num -= digit * digit_value;
        *pos++ = '0' + digit;
        digit_value /= base;
    }
    *pos = '\0';
    return str;
}

EDIT:
Alıntı
sprintf() is the easiest way to do this in most cases. It may seem odd that itoa() is not standard when atoi() is, but apparently the standards committee felt that the former wasn't as portable as the latter (at least I seem to recall that being part of the reason). Also, whereas atoi() can return an integer value as a function, itoa() would need to either take a char buffer to write the values into (as the usual version does), or else allocate a string dynamically and return that (which goes against the general design principles of the standard library, which usually avoids dynamic allocation wherever possible).
Başlık: GP2X Standart Library Eksikleri
Gönderen: skate - 29.05.2007 15:23:09
Turbo C'den bu yana hep kullandığım bir fonksiyondur ve STDLIB'in içinde yer alır. Standart dışı olduğu bir an için bile aklıma gelmemişti. Bilgi için teşekkürler Gnostic.