I am in my first (and last) C++ class and this week we have to write a program to compare two IP addresses to determine what the class of the IP address is. I have the code working for classes a, b, & c. The problem I am having is trying to code class d & e. I have the code below. Can someone help me?
I am going to put this into a function (FindClass) after I get the logic working. (Any help with making this function functional is appreciated!!!)
Code:
#include <iostream.h>
#include <string>
#include <fstream.h>
using namespace std;
char *addcl;
//int FindClass(*addcl);
//{
//
// if(0 < ip[0] && 127 >= ip[0])
// {
// *addcl = 'a';
// }
// else if(128 <= ip[0] && ip[0] <= 191)
// {
// *addcl = 'b';
// }
// else if(192 <= ip[0] && 223 >= ip[0])
// {
// *addcl = 'c';
// }
// else
// {
// *addcl = 'n';
// }
// return (*addcl);
//}
void main(int ip[], char *addcl)
{
int ip1[3], ip2[3];
cout << "Please enter an ip address, using spaces between each octet. : ";
cin >> ip1[0] >> ip1[1] >> ip1[2] >> ip1[3];
// cout << "Please enter an ip address, using spaces between each octet. : ";
// cin >> ip2[0] >> ip2[1] >> ip2[2] >> ip2[3];
// if(111 == ip1[0] && 99 <= ip1[1])
// {
// *addcl = 'd';
//
// else (111 == ip1[0] && 99 > ip1[1])
// *addcl = 'e';
// }
if(0 < ip1[0] && 127 >= ip1[0])
{
*addcl = 'a';
}
else if(128 <= ip1[0] && ip1[0] <= 191)
{
*addcl = 'b';
}
else if(192 <= ip1[0] && 223 >= ip1[0])
{
*addcl = 'c';
}
else
{
*addcl = 'n';
}
cout << "IP Addr #1: " <<ip1[0]<<"." <<ip1[1]<<"."<<ip1[2]<<"."<<ip1[3]<<endl;
// cout << "IP Addr #2: " <<ip2[0]<<"." <<ip2[1]<<"."<<ip2[2]<<"."<<ip2[3]<<endl;
cout << *addcl<<endl;
// FindClass(ip1[0]);
// FindClass(ip2[0]);
}
THANKS AGAIN!