#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//192.168.44.5 转 0xc0a82c05
//0c a8 2c 05
int toInt(const char *str)
{
int num = 0;
char buf[20] = {0};
strcpy( buf , str );
char *s = strtok( buf , ".");
while( s != NULL )
{
num = (num << 8) + atoi( s );
s = strtok( NULL ,".");
}
return num;
}
int main()
{
char *s = "192.168.44.5";
int ret = toInt( s );
printf("ret = %x\n" , ret);
return 0;
}
C语言ip地址转十六进制
于 2021-12-22 08:42:21 首次发布