string判断是否是正常的ip格式

废话不多说,上代码

bool isCurrectIP(char *ip)
{
	if (ip == NULL)
	{
		return false;
	}
	char temp[4];
	int count = 0;
	while (true)
	{
		int index = 0;
		while (*ip != '' && *ip != '.' && count < 4)
		{
			temp[index++] = *ip;
			ip++;
		}
		if (index >= 4)
		{
			return false;
		}
			
		temp[index] = '';
		int num = atoi(temp);
		if (!(num >= 0 && num <= 255))
		{
			return false;
		}
		count++;
		if (*ip == '')
		{
			if (count == 4)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			ip++;
		}
	}
}

  

原文地址:https://www.cnblogs.com/132818Creator/p/11157903.html