string判断是否是正常的ip格式
生活随笔
收集整理的這篇文章主要介紹了
string判断是否是正常的ip格式
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
廢話不多說(shuō),上代碼
bool isCurrectIP(char *ip)
{if (ip == NULL){return false;}char temp[4];int count = 0;while (true){int index = 0;while (*ip != '\0' && *ip != '.' && count < 4){temp[index++] = *ip;ip++;}if (index >= 4){return false;}temp[index] = '\0';int num = atoi(temp);if (!(num >= 0 && num <= 255)){return false;}count++;if (*ip == '\0'){if (count == 4){return true;}else{return false;}}else{ip++;}}
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/132818Creator/p/11157903.html
總結(jié)
以上是生活随笔為你收集整理的string判断是否是正常的ip格式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 随心测试_软测基础_005 测试人员工作
- 下一篇: NOIP2012 DAY1 T2 国王游