#include <stdio.h>
unsigned long ip;
int judge(int ,int ,int ,int);
void main()
{
char *ipstr[50];
int a,b,c,d;
printf("please input a ip\n");
scanf("%s",ipstr);
sscanf(ipstr,"%d.%d.%d.%d",&a,&b,&c,&d);
if(judge(a,b,c,d))
{
ip=inet_addr(ipstr);
printf("the int ip is %ld\n",ip);
}
else
printf("is not ip\n");
}
int judge(int a,int b, int c, int d)
{
if (a < 0)
return 0;
if (a > 255)
return 0;
if (b < 0)
return 0;
if (b > 255)
return 0;
if (c < 0)
return 0;
if (c > 255)
return 0;
if (d < 0)
return 0;
if (d > 255)
return 0;
return 1;
}
please input a ip
12.13.14.15
the int ip is 252579084
因篇幅问题不能全部显示,请点此查看更多更全内容