#includeint is_valid_ip(const char *ip) { int section = 0; //每一节的十进制值 int dot = 0; //几个点分隔符 int last = -1; //每一节中上一个字符 while(*ip) { if(*ip == '.') { dot++; if(dot > 3) { return 0; } if(section >= 0 && section <=255) { section = 0; }else{ return 0; } }else if(*ip >= '0' && *ip <= '9') { section = section * 10 + *ip - '0'; if(last == '0') { return 0; } }else{ return 0; } last = *ip; ip++; } if(section >= 0 && section <=255) { if(3 == dot) { section = 0; printf ("IP address success!\n"); //printf ("%d\n",dot); return 0; } } return 1; } int main() { is_valid_ip("192.249.23.123"); }