实现网络地址去掉小数点后输出

要求:

请写一段代码,可以将输入为”0.0.0.0”—“255.255.255.255”的字符串转换为int型整数数组。

输入:”255.255.255.255”

输出:255 255 255 255 (数组)

void transform(char* str)
{
	int i;
    int len = strlen(str);
	int res[20] = {-1};
	int j = 0;
	
    for(i = 0; i  < len; i++)
    {
		int tmp = ((int)str[i]-(int)'0');

		if(tmp >=0 && tmp <= 9)
		{
			res[j++] = tmp;
			printf("%d",tmp);
		}
		if(str[i] == '.')
			printf(" ");
			
    }
	
}

猜你喜欢

转载自blog.csdn.net/weixin_42596333/article/details/112997201