1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream> //needed for cout and cin
#include <fstream> // needed for opening, reading, and closing a file.
#include <string> // needed for processing string data types
using namespace std; //not really sure what this does, but I always use it
void tableinsert(string DN, string IP, string DNarray[], string IParray[], int size); //prototype for tableinsert function
int searchTable(string array[], string FindMe, int& size); //prototype for the searchTable function.
int main() //main function
{
const int SIZE = 10; //setting a constant value for the arrays,just in case it ever needs changing
string file_Name; //what the file shall be none as when read in
ifstream InFile; //used for bringing stuff in from the file
ofstream OuFile; //used for bringing stuff out. Might be deleted if not used.
char symbol; //where it stores the "=" and "?"
string DNS_Address[SIZE]; //array for storing the DNS addresses
string IP_Address[SIZE]; //array for storing IP addresses
int ctr = 0; //counter for ending the for loop.
cout << "Please enter the name of the file to process: "; //nice message asking for the name of the file
cin >> file_Name; //reading in the file name.
InFile.open(file_Name.c_str()); //opening the file
if(InFile.is_open() == false) //if the file doesn't exist, then it tells the user in a polite manner.
{
cout << "Sorry, there must be a mistake, there is no such file!" << endl; //polite message.
return 1; //fail
}
InFile >> symbol; //reading in the first char "symbol"
for(ctr = 0; ctr < SIZE; ctr++)
{
if(symbol == '=')
{
cout << "Proccessing " << symbol << endl;
InFile >> DNS_Address[ctr];
InFile >> IP_Address[ctr];
}
else
{
cout << "Processing " << symbol << endl;
}
InFile >> symbol;
}
return 0;
} // end of main function
void tableinsert(string DN, string IP, string DNarray[], string IParray[], int size) //function that places the data into a table
{
int DNindex = searchTable(DNarray, DN, size); //uses the searchTable function to returna value
if(DNindex!= -1)
{
IParray[DNindex] = IP;
}
else
{
//put into the array
size++;
}
}
int searchTable(string array[], string FindMe, int& size)
{
for(int t = 0; t < size; t++)
{
if(array[t] == FindMe)
{
return t;
}
}
return -1;
}
| |