F
Francis Bell
Hello,
I'm trying to read data from a file and then insert that into a linked
list. The way I have it, the program compiles, however, I'm getting a
segmentation fault error message when I run the program. I'm fairly new
at the pointer business, and I'd appreciate any advice. Here's my code:
int main()
{
ifstream fin;
Fish fishy;
FishLinkedList lake;
fishy.readFishData(fin);
while (!fin.fail()) {
lake.insertAtHead(fishy);
fishy.readFishData(fin);
}
fin.clear();
fin.close();
}
void Fish::readFishData(istream &sin) {
getline(sin, type, '/');
sin >> weight;
sin.ignore(80, '\n');
}
void FishLinkedList::insertAtHead(Fish fishy)
{
if (head != NULL) { // there is a list
Fish *temp = head;
Fish *insertMe = &fishy;
temp->setNext(insertMe);
} else {
head = &fishy;
}
}
Thanks!
Frank
I'm trying to read data from a file and then insert that into a linked
list. The way I have it, the program compiles, however, I'm getting a
segmentation fault error message when I run the program. I'm fairly new
at the pointer business, and I'd appreciate any advice. Here's my code:
int main()
{
ifstream fin;
Fish fishy;
FishLinkedList lake;
fishy.readFishData(fin);
while (!fin.fail()) {
lake.insertAtHead(fishy);
fishy.readFishData(fin);
}
fin.clear();
fin.close();
}
void Fish::readFishData(istream &sin) {
getline(sin, type, '/');
sin >> weight;
sin.ignore(80, '\n');
}
void FishLinkedList::insertAtHead(Fish fishy)
{
if (head != NULL) { // there is a list
Fish *temp = head;
Fish *insertMe = &fishy;
temp->setNext(insertMe);
} else {
head = &fishy;
}
}
Thanks!
Frank