I have a error with a nodeType. I believe it is just one line. The error says "[Linker error] undefined reference to `insert(nodeType*,std::basic_ifstream<char,std::char_traits"
and "Id returned 1 exit status"
This line is the part of code that i believe is wrong.
nodeType *insert(nodeType *list, ifstream& inFile);
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct surf_info
{
string domain;
string ip;
int counter;
};
typedef surf_info infoType ;
struct nodeType
{
infoType info;
nodeType *link;
};
void header ();
nodeType *insert(nodeType *list, ifstream& inFile);
void modify(nodeType *list, ifstream& inFile);
void remove(nodeType *list, ifstream& inFile);
void find(nodeType *list, ifstream& inFile);
void print(nodeType *list);
void print_zero(nodeType *list );
void print_huge (nodeType *list);
void print_file(nodeType *list);
int main()
{
char command;//I,M,R,F,P;
ifstream inFile;
string file;
nodeType *line;
header ();
cout<<"Please enter a file you would like to use..."<<endl;
cin>>file;
inFile.open(file.c_str());
if(!inFile)
{
cout << "\n\nError! - Invalid Filename! (1)\n\n";
system ("pause");
return 1;
}
else
{
int count=0;
inFile>>command;
line=NULL;
while ( command != 'X')
{
cout << command<<endl;
if (command =='I'){
line= insert (line, inFile);
//inFile >> temp.domain >>temp.ip;
//add to end of the array // make sure count is set zero
}
else if ( command =='M'){
modify (line,inFile);
//inFile >> temp.domain >> temp.ip;
//change ip of domain to newIP
//message if item is not in the array
//increment the counter
}
else if (command =='R'){
remove(line,inFile);
//inFile >> temp.domain;
//remove entry with that domain name from the array
//message if item is not in the array
}
else if (command =='F'){
find (line, inFile);
//inFile >> temp.domain;
//find entry with indicated domain name and print the ip
//increment the counter
//message if item is not in the array
}
else if (command =='P'){
print(line);
//print the array
}
inFile >> command;
}
}
cout<<endl<<endl;
print(line);
cout<<endl;
print_zero(line);
cout<<endl;
print_huge (line);
cout<<endl;
print_file(line);
system("pause");
return 0;
}
//----------------------------------------------------------------------------------
void header ()
{
cout<<"Source file: To use link list with Project 4"<<endl;
cout<<"Name: Chris CUmmings"<<endl;
cout<<"Date: 4/18/2010 "<<endl;
cout<<"Lab CRN: 10945 "<<endl;
cout<<"==================================================================="<<endl;
}
//----------------------------------------------------------------------------------
nodeType *in (nodeType *list, ifstream& inFile)
{
nodeType *flap;
flap= new nodeType;
inFile >> flap->info.domain >>flap->info.ip;
flap->info.counter=0;
flap->link=NULL;
cout<<flap->info.domain<<" "<<flap->info.ip<<endl;
flap->link=list;
list =flap;
return list;
}
//----------------------------------------------------------------------------------
//
void modify (nodeType *list, ifstream& inFile)
{
nodeType *updata;
string name1,name2;
bool found = false;
inFile >> name1>> name2;
cout<<name1<<name2<<endl;
updata = list;
while (updata != NULL)
{
cout<<updata->info.domain<<endl;
if(updata->info.domain==name1){
updata->info.ip =name2;
cout << updata->info.ip;
updata->info.counter++;
found=true;
}
updata=updata->link;
}
cout << endl;
if(found==false)
cout<<"Did not find!"<< name1<< endl;
}
//----------------------------------------------------------------------------------
void remove(nodeType *list, ifstream& inFile)
{
nodeType *current;
nodeType *past;
string name;
inFile >> name;
cout<<name<<endl;
current = list;
if(current->info.domain==name)
list=current->link;
else
{
past=list;
current=current->link;
while (current != NULL)
{
if(current->info.domain==name)
{
past->link=current->link;
}
past=current;
current=current->link;
}
cout << endl;
}
}
//---------------------------------------------------------------------------------
void find (nodeType *list, ifstream& inFile)
{
nodeType *current;
string name;
bool found = false;
inFile >> name;
cout<<name<<endl;
current = list;
while (current != NULL)
{
if(current->info.domain==name){
cout << current->info.ip;
current->info.counter++;
found=true;
}
current=current->link;
}
cout << endl;
if(found==false)
cout<<"Can not find!!!"<<endl;
}
//---------------------------------------------------------------------------------
void print(nodeType *list)
{
nodeType *current;
current = list;
while (current != NULL)
{
cout<< current->info.domain<<" "<< current->info.ip<<" "<< current->info.counter<<endl;
// cout<<current->link;
current=current->link;
}
}
//--------------------------------------------------------------------------------
void print_zero(nodeType *list )
{
nodeType *current;
current=list;
cout<<"List entries with a zero counter:"<<endl;
while(current!=NULL)
{
if(current->info.counter==0)
{
cout<<current->info.counter;
current=current->link;
}
else
current=current->link;
}
}
//-------------------------------------------------------------------------------
void print_huge (nodeType *list)
{
int file=0;
nodeType *current;
nodeType *big;
current=list;
cout<<"List entry with the largest counter:"<<endl;
while(current!=NULL)
{
if(current->info.counter>file)
{
big=current;
file=current->info.counter;
current=current->link;
}
else
current=current->link;
}
cout<<big->info.domain<<" "<<big->info.ip<<" "<<big->info.counter<<endl;
}
//-------------------------------------------------------------------------------
void print_file(nodeType *list){
ofstream outFile;
outFile.open("Cummings.txt");
outFile<<"Source file: To use link list with Project 4"<<endl;
outFile<<"Name:"<<endl;
outFile<<"Date: "<<endl;
outFile<<"Lab CRN: "<<endl;
outFile<<endl;
outFile<<"Final List:"<<endl;
nodeType *current;
current = list;
while (current != NULL)
{
outFile<<"Domain : "<<current->info.domain<<endl;
outFile<<"IP address: "<<current->info.ip<<endl;
}
outFile.close();
}