【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
#include<stdio.h>
int a2dt(const char* str)
{
int a;
unsigned char* ap= (unsigned char*)&a;
sscanf(str,"%d.%d.%d.%d",ap,ap+1,ap+2,ap+3);
return a;
}
char * dt2a(int a)
{
char *s = new char[14];
unsigned char* ap= (unsigned char*)&a;
sprintf(s,"%u.%u.%u.%u",ap[0],ap[1],ap[2],ap[3]);
return s;
}
int main()
{
unsigned int a = a2dt("8.7.6.5");
char * ap = dt2a(a);
printf("%0p\n",a);
printf("%s\n",ap);
return 0;
}
来源:oschina
链接:https://my.oschina.net/u/3695598/blog/3151272