Linked List Trouble

I have a program that takes an input file and stores it into a linked list. I'm having trouble with my load function and my add function. It's a big program with 5 files, so I'll just post the functions.

add function:

void College::add(course c){
cout << "Enter course info." << endl;
cin >> c;

node* tmp;
if(head == NULL){
head = new node;
head->set_data(c);
head->set_link(NULL);
}
else{
for(tmp = head; tmp != NULL; tmp = tmp->link()){
tmp->set_link(new node);
tmp = tmp->link();
tmp->set_data(c);
tmp->set_link(NULL);
}
}
}

load function:

void College::load(istream& ins){
course tmp;
while(ins >> tmp){
add(tmp);
}
}

Add is being called in my main each time you want to add something to the list but I don't know how to not have add in my load function and still be able to store a txt file in my list.
add needs to not read from the keyboard, if I understand your question.
that is, in main you can read in the course info and THEN call add with what you read in, and in load you can call it with what was in the file. Your trouble is that you read data in the add routine, so load from file requires keyboard input which is not useful.

or you can make another function 'getuserinput' or something to read the data from the keyboard and then call add -- the point is just to get that read out of add.

Topic archived. No new replies allowed.