#include
#include
char *long2ip(u_long in);
u_long ip2long(char *ip);
int main()
{
char p[16];
printf("请输入IP地址:\n");
scanf("%s",p);
u_long l = ip2long(p);
printf("%s\n",long2ip(l));
int inum = 0 ;
scanf("%d",inum);
return 0;
}
char *long2ip(u_long in)
{
u_char *p;
p = (u_char*)(&in);
static char output[16];
_snprintf_s(output,16,16,"%d.%d.%d.%d",p[0],p[1],p[2],p[3]);
return output;
}
u_long ip2long(char *ip)
{
u_char addr[16];
sscanf(ip,"%d.%d.%d.%d",addr,addr+1,addr+2,addr+3);
u_long *vl = (u_long*)(&addr);
return *vl;
}