Save it temporarily and test it later
// Determine whether an IP address is valid for 2 h <br/> void main (void) <br/>{< br/> char s [16]; <br/> memset (S, '/0', 16); <br/> int IP Address [5] = {0, 0, 0 }; <br/> int I = 0, j = 0, Count = 0; <br/> cout <"Please input an IP address/N "; <br/> CIN> S; <br/> int strlenth = strlen (s ); // 15 </P> <p> // cout <strlenth <Endl; </P> <p> If (strlenth> 15) <br/> {// The maximum length is 15 <br/> cout <"Invalid Address/N"; <br/> exit (0 ); <br/>}</P> <p> else <br/> {<br/> for (I = 0; I <s Trlenth; I ++) <br/>{< br/> If (S [I]> '0' & S [I] <'9 ') | (s [I] = '. '))&&! Strstr (S ,".. ") // All are numbers or dots, and there are no Links <br/>{< br/> // convert to a value <br/> If (s [I] = '. ') <br/>{< br/> count ++; <br/> J ++; <br/>}< br/> else <br/> IP [J] = IP [J] * 10 + (s [I]-'0 '); <br/>}< br/> else <br/>{< br/> cout <"Invalid Address/N"; <br/> exit (0 ); <br/>}< br/> If (count> 3) <br/> {// too many segments <br/> cout <"Invalid Address/N"; <br/> exit (0 ); <br/>}< br/> // cout <IP [0] <'. '<IP [1] <'. '<IP [2] <'. '<IP [3] <Endl; </P> <p> for (j = 0; j <4; j ++) <br/> {// determine the value range <br/> If (IP [J]> 255) <br/>{ <br/> cout <"Invalid Address/N"; <br/> exit (0 ); <br/>}< br/> cout <"valid address/N"; <br/>}< br/>}