#include <stdio.h>
#include <string.h>
bool isIP(const char* str);
int main()
{
char str[] = "111.111.111.21";
char str2[] = "a.111.111.111";
char str3[] = "11.1.1.1.d";
printf("%d
",isIP(str));
printf("%d
",isIP(str2));
printf("%d
",isIP(str3));
}
bool isIP(const char* str)
{
int a,b,c,d;
char temp[100];
if((sscanf(str,"%d.%d.%d.%d",&a,&b,&c,&d))!=4)
return false;
sprintf(temp,"%d.%d.%d.%d",a,b,c,d);
if(strcmp(temp,str) != 0)
return false;
if(!((a <= 255 && a >= 0)&&(b <= 255 && b >= 0)&&(c <= 255 && c >= 0)))
return false;
else
return true;
}