Realize the output after removing the decimal point of the network address

Claim:

Please write a piece of code to convert the string entered as "0.0.0.0"-"255.255.255.255" into an int type integer array.

Input: "255.255.255.255"

Output: 255 255 255 255 (array)

 

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(" ");
			
    }
	
}

 

Guess you like

Origin blog.csdn.net/weixin_42596333/article/details/112997201