Home > Back-end >  Small white do C natural classification the IP address of the judgment
Small white do C natural classification the IP address of the judgment

Time:11-20

The natural classification C IP address I do judgment, the HTML code is as follows, the abcd respectively used to represent each IP address, set the "e" is in order to determine whether more entered the period of using,
B, c, d is one of them is 1 explain without success gives value, so judge input errors such as input 1. A. 1.1, 1.2, 2.3, e!=- 6123 shows that the value of e changed, but should not be assigned in paragraph 5, so that more input, the other is to enter the Numbers beyond limit,


 # include & lt; stdio.h> 
The main ()
{
Int a=1, b=1, c=1, d=1, e=6123;
//set the initial value is to determine the IP address entered when input format is correct, if does not have some typos
//namely actually I technology is not enough, only to avoid bugs in this way,
Printf (" \ n ");
Printf (" please enter the IP address: ");
The scanf (" % d, % d, % d, % d, % d ", & amp; A, & amp; B, & amp; C., & amp; D, & amp; E);
Printf (" \ n ");
If (((a<0 | | a> 255) | | (b<0 | | b> 255) | | (c<0 | | c> 255) | | (d<0 | | d> 255) | | e!=- 6123))
{
If (==1 b | | c==1 | | d==1)
{
Printf (" IP address input error, please enter the digits or not enter dotted decimal!" );
}
Else if (e!=- 6123)
{
Printf (" input address of too much!" );
}
The else
{
Printf (" IP address illegal! Please enter a number between 0 and 255 ");
}
}
The else
{
If (a> 0& & a<127)
{
If (b==0 & amp; & C==0 & amp; & D==0)
{
Printf (" % d, % d, % d, % d is A kind of address, and is the address of the network address ", A, b, c, d);
}
Else if (b==255 & amp; & C==255 & amp; & D==255)
{
Printf (" % d, % d, % d, % d is A kind of address, and is the broadcast address of the address ", A, b, c, d);
}
The else
{
Printf (" % d, % d, % d, % d is A kind of address ", A, b, c, d);
}
}
Else if (a> 127 & amp; & a<192)
{
If (c==0 & amp; & D==0)
{
Printf (" % d, % d, % d, % d is a class B address, and is the address of the network address ", a, B, c, d);
}
Else if (c==255 & amp; & D==255)
{
Printf (" % d, % d, % d, % d is a class B address, and is the broadcast address of the address ", a, B, c, d);
}
The else
{
Printf (" % d, % d, % d, % d is a class B IP address ", a, B, c, d);
}
}
Else if (a> 191 & amp; & a<224)
{
If (d==0)
{
Printf (" % d, % d, % d, % d is a class C IP address, and is the address of the network address ", a, b, C, d);
}
Else if (d==255)
{
Printf (" % d, % d, % d, % d is a class C IP address, and is the broadcast address of the address ", a, b, C, d);
}
The else
{
Printf (" % d, % d, % d, % d is a class C address ", a, b, C, d);
}
}
Else if (a> 223 & amp; & a<240)
{
Printf (" % d, % d, % d, % d is a class d address (multicast address) ", a, b, c, d);
}
Else if (a> 239 & amp; & a<255)
{
Printf (" % d, % d, % d, % d is a class E address (addresses) ", a, b, c, d);
}
Else if (a==0)
{
If (b==0 & amp; & C==0 & amp; & D==0)
{
Printf (" % d, % d, % d, % d is for the default route ", a, b, c, d);
}
The else
{
Printf (" % d % d, % d, % d illegal! Starting IP address cannot be 0 unless all bits are 0 ", a, b, c, d);
}
}
Else if (a==255)
{
If (b==255 & amp; & C==255 & amp; & D==255)
{
Printf (" % d, % d, % d, % d is cut in the broadcast address (basic unavailable) ", a, b, c, d);
}
The else
{
Printf (" % d % d, % d, % d cannot be used! IP address at the beginning to 255 unless all bits are 255 ", a, b, c, d);
}
}
The else
{
Printf (" % d, % d, % d, % d is a loopback address ", a, b, c, d);
}
}
}

CodePudding user response:

My first post and my technology is not strong, just to share
  • Related