[Cexpert-001] How to implement atoi with least codes using C language?

鍾超發表於2012-04-04

It's soooo easy, I think.


#include <stdio.h>

int atoi(unsigned char *str)
{
   int num = 0;
   while (*str >= '0' && *str <= '9') num = num * 10 + *str++ - '0';
   return num;
}

int main(void)
{
   printf("%d\n", atoi("12345"));
   return 0;
}

So easy, right?

-

Poechant

-

相關文章