现在的位置: 首页 > 综合 > 正文

atoi 变型- 有意思,留存

2013年08月30日 ⁄ 综合 ⁄ 共 632字 ⁄ 字号 评论关闭

#include <stdio.h>
#include <unistd.h>
static char* _intoaV4(unsigned int addr, char* buf, unsigned short bufLen)
{
  char *cp, *retStr;
  unsigned int byte;
  int n;

  cp = &buf[bufLen];
  *--cp = '/0';
  n = 4;
  do
  {
    byte = addr & 0xff;
    *--cp = byte % 10 + '0';
    byte /= 10;
    if (byte > 0)
    {
      *--cp = byte % 10 + '0';
      byte /= 10;
      if (byte > 0)
      {
        *--cp = byte + '0';
      }   
    }
    *--cp = '.';
    addr >>= 8;
  } while (--n > 0);

  /* Convert the string to lowercase */
  retStr = (char*)(cp+1);
    printf("%s/n",retStr);
  return(retStr);
}
int main()
{//_intoaV4(stbcapChannel.channelAddr,buf1,32),
 char str[100]="";
 char *ss;
 ss=_intoaV4(142454,str,32);
  printf("%s/n",ss);
    getchar();
    return 0;
    }

抱歉!评论已关闭.