#include <stdio.h>
#include <string.h>
// www.outofmemory.cn
int main(void)
{
char str[31],temp[31];
int a,b,c,d;
while(gets(str)!=NULL)
{
if(sscanf(str, "%d.%d.%d.%d ",&a,&b,&c,&d)==4 && a>=0 && a<=255 && b>=0 && b<=255 && c>=0 && c<=255 && d>=0 && d<=255)
{
sprintf(temp, "%d.%d.%d.%d",a,b,c,d); //把格式化的数据写入字符串temp
if(strcmp(temp,str)==0)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
else
{
printf("NO\n");
}
}
return 0;
}
C语言判断给定的字符串是否为合法的ip地址
最新推荐文章于 2021-07-17 23:23:35 发布