自己动手将整数转换字符串

#include <stdio.h>
void strrev(char *s)
{
    char *p=s,t;
    if(*p)
      while(p[1])
          p++;
    while(s<p)
    {
        t=*s;
        *s++=*p;
        *p--=t;
    }
}
char* itoa(int num,char *result)
{
    int i=0;
    while(num)
    {
        result[i++] = num%10 + '0';
        num /= 10;    
    }
    result[i]=0;
    strrev(result);
    return result;
}
void main ()
{
    char s[12];
    puts( itoa(12345446,s) );
}

 

posted @ 2013-07-23 16:40  Please Call me 小强  阅读(222)  评论(0编辑  收藏  举报