C++Guns – RoboBlog

30.12.2008

atoull atoul

Filed under: programmieren — Thomas @ 18:12

Erschreckend musste ich heute feststellen, dass die libc gar keine atoull Funktion mitbringt, sondern nur eine atoll. Das Problem lässt sich aber einfacher lösen als gedacht. Hier die Funktion in zwei Varianten.

void atoull(char *s, unsigned long long *n)
{
*n = 0;
while ('0' <= *s && *s <='9')
*n = (*n)*10 + *s++ - '0';
}

unsigned long long atoull(char *s)
{
unsigned long long n = 0;
while ('0' <= *s && *s <='9')
n = n*10 + *s++ - '0';
return n;
}

void atoul(char *s, unsigned long *n)
{
*n = 0;
while ('0' <= *s && *s <='9')
*n = (*n)*10 + *s++ - '0';
}

unsigned long atoul(char *s)
{
unsigned long n = 0;
while ('0' <= *s && *s <='9')
n = n*10 + *s++ - '0';
return n;
}

Viel Spass damit :)

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress