My code complies fine but freezes when i try to run it.
I Believe the error is somewhere between lines 82-115
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
struct domList
{
string domName;
string ipAddress;
int counter;
};
void insertOne(domList list[], ifstream& inFile, int len);
void change(domList list[], string dName, string IpNum, int len);
void Delete(domList list[], string dName, int& lengthList);
void Find(domList list[], string dName, int len);
void Print (domList list[], int len);
void Quit (domList list[], int len);
void topDom(domList list[], int len);
int main (){
char command;
domList list[100];
int listLength = 0;
string ipNum, DomName;
int counter = 0;
bool x;
ifstream dataFile;
//stores the name of the dataFile
string dataFile1;
cout << "Please enter the data file you wish to use: ";
cin >> dataFile1;
dataFile.open (dataFile1.c_str());
if (!dataFile)
{
cout << "bummer file\n\n";
system ("pause");
return 1;
}
while(!dataFile.eof()){
dataFile >> command;
if(command == 'A')
{
insertOne(list, dataFile, listLength);
listLength++;
}
else if(command == 'M')
{
change(list, DomName, ipNum, listLength);
}
else if(command == 'D')
{
Delete(list, DomName, listLength);
listLength--;
}
else if(command == 'F')
{
Find(list, DomName, listLength);
}
else if(command == 'P')
{
Print(list, listLength);
}
else if(command == 'Q')
{
Quit(list, listLength);
Print(list, listLength);
}
}
dataFile.close();
cout << endl << endl << endl;
topDom(list, listLength);
int high = list[0].counter;
for (int i = 1; i < listLength; i++)
{
if(list[i].counter > high)
{
high = list[i].counter;
}
}
cout << "The domain with the highest counter is: "
<< high << endl;
ofstream out;
out.open("info.txt");
for (int i = 0; i < listLength; i++)
{
out << setw(23) << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
out << "Programmed By: Chris Cummings" << endl;
out << "Date: 11/10/2011" << endl;
out << "Lab CRN: 10945" << endl;
out.close();
system("pause");
return 0;
}
void insertOne(domList list[], ifstream& inFile, int len)
{
domList one;
inFile >> one.domName >> one.ipAddress;
one.counter = 0;
list[len] = one;
}
void change(domList list[], string dName, string IpNum, int len)
{
for(int i = 0; i < len; i++)
{
if(list[i].domName == dName)
{
list[i].ipAddress = IpNum;
list[i].counter += 1;
}
}
}
void Delete(domList list[], string dName, int& lengthList)
{
for(int i = 0; i < lengthList; i++)
{
if(list[i].domName == dName)
{
for(int l = i; l < lengthList; l++)
{
list[l] = list[l+1];
lengthList--;
}
}
}
}
void Find(domList list[], string dName, int len)
{
for (int i = 0; i < len; i++)
{
if (list[i].domName == dName)
{
cout << "The ip Address for " << list[i].domName
<< " is " << list[i].ipAddress << endl;
list[i].counter += 1;
}
}
}
void Print (domList list[], int len)
{
cout << "\n\n\nPrinting" << endl;
for (int i = 0; i < len; i++)
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
void Quit (domList list[], int len)
{
domList one, two;
int min, temp;
for(int i = 0; i < len; i++)
{
min = i;
for(int l = 1; l < len; l++)
{
if(list[l].domName.substr(5,5) < list[i].domName.substr(5,5))
min = l;
}
one = list[i];
list[i] = list[min];
list[min] = one;
}
}
void topDom(domList list[], int len)
{
int edu, com, org, net, largest;
string highest;
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "edu")
edu++;
else if(list[i].domName.substr(len-3, len) == "com")
com++;
else if(list[i].domName.substr(len-3, len) == "org")
org++;
else if(list[i].domName.substr(len-3, len) == "net")
net++;
}
if(edu > com && edu > org && edu > net)
{
cout << ".edu is the most popular domain with " << edu << endl;
cout << "List of .edu domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "edu")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(com > edu && com > org && com > net)
{
cout << ".com is the most popular domain with " << edu << endl;
cout << "List of .com domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "com")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(org > edu && org > com && org > net)
{
cout << ".org is the most popular domain with " << edu << endl;
cout << "List of .org domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "org")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
else if(net > edu && net > com && net > org)
{
cout << ".net is the most popular domain with " << edu << endl;
cout << "List of .net domains";
for (int i = 0; i < len; i++)
{
if(list[i].domName.substr(len-3, len) == "net")
{
cout << setw(23) << left << list[i].domName << setw(20)
<< list[i].ipAddress << setw(6)
<< list[i].counter << endl;
}
}
}
}