doubly linked list

hey guys so i seem to be having issue with my code, We need to make a doubly circularly linked list, but i cannot for the life of me seem to get my populate function to work with my add name function any ideas



#include <iostream>
#include <fstream>
using namespace std;

string fname, lname;
int year;

struct entry_t{
string fname;
string lname;
string entry;
int year;
entry_t *next;
entry_t *previous;
};
entry_t *List = NULL;
entry_t *HEAD = NULL;
string entry;

void addname(ifstream &infile, string fname, string lname, int year){
entry_t *temp = List;


if(List != 0){

entry_t *temp = List->next;
entry_t *temp2 = List;
int found = 0;

for(temp = List; temp != NULL; temp = temp->next, temp2 = temp2->next){
temp->next = new entry_t; // takes the pointer and tells it to go to the next entry
temp->next->fname = fname;
temp->next->lname = lname;
temp->next->year = year;
cout << endl;
temp->next->next = 0;
temp->next->previous = temp; // this is how it goes backwards which is important to the doubly linked list

}
}

else{
// if there is no list then make one
HEAD = new entry_t;
HEAD->fname = fname;
HEAD->lname = lname;
HEAD->year = year;
HEAD->next = 0;
HEAD->previous = 0;

}


}







void populate(string fname, string lname, int year){
ifstream infile("football.txt");
while(!infile.eof()){
infile>>fname>>lname>>year;
cout<<fname<<" "<<lname<<" "<<year;
cout<<endl<<endl;
void addname(fname, lname, year);
}
}


void remove(){}

void deleteList(){ // you will need two pointers to delete things from the list
if(List){
entry_t *tempDelete = List;
entry_t *tempHolder = tempDelete->next; // lots of the faults will come from this section of the code
while(tempDelete != 0){
delete tempDelete;
tempDelete = tempHolder;
if(tempHolder)
tempHolder = tempHolder->next;
}
}
}

void print(){

for(entry_t *temp = List; temp != 0; temp = temp->next){
cout << temp->fname << temp->lname << temp->year << endl;
}

}
void search(){}


int main(){
entry_t HEAD;

int choice = 0;
while(1){
cout << " 1 to populate list s \n 2 to remove player \n 3 to print list \n 4 to exit \n 5 to search \n 6 to addname \n ";

cin >> choice;



switch(choice){
case 1: populate(fname,lname,year); break;
case 2: remove(); break;
case 3: print(); break;
case 4: deleteList(); break;
case 5: search(); break;
case 6: addname(); break;
default: cout << "Invalid number.";
}
if(choice == 4){
break;
}
}
return 0;
}
Last edited on
When you can't get something to compile, it is customary to indicate that is the problem and to provide the errors supplied to you by the compiler. The more specific about the issue you're having, the easier it is to help you.

Your definition of addname requires 4 arguments. You aren't giving it 4 arguments when you call it. Also, when calling a function, arbitrarily placing void in front of it's invocation is not recommended.

Yes i have gotten to the point that i am having segmentation faults now when i try an populate my list. I have been using GDB to try and find my issues but it is just causing me to find more and more errors.

thank you I have already fixed the things from your advice before. When i posted this code i was ready to just quit life. I seem to be making some progress but still have the same issue with getting it to run. I have no compile errors anymore just segmentation faults.
Topic archived. No new replies allowed.