file i/o, struct, linked list and segmentation fault

Hi folks,

Sorry this is long. I didn't want to be a "HAI GUYS, HERES MY CODE PLZ HLP" poster. I've been up all night with my C++ Lab and I'm looking for some guidance.

I was following the instructor's linked list walkthrough, but he left some things up to us students. Understandable. Though I can't figure out how to get around these errors and I'm looking for insight, not someone to do my homework for me.

The program is supposed to read an unknown number of lines from a .txt file, storing each line's items into objects in a struct, then lists outputs them to the screen. Later I'll have to make an object for each of the items, food name, food group, calories and daily percentage, and sort out the high calorie items if the user decides they want to do that. For now I just want to get the items into my struct, then output them on screen.

while(inFile >> next) isn't working for me because "next was not declared in this scope." A google search gave me answers that went over my head (We haven't done classes yet) and no alternative approaches.

Using inFile >> temp->id and such for each item on a line gets me a segmentation fault, though I think I'm using inFile.close() in the correct place. My debugger skips over the whole loop, even though the loop's output shows up on screen, along with extra unwanted output.

I really tried to trim this post down, but I wanted to be thorough and not just throw a bunch of code out for you to sift through. I appreciate any help. Here are the .cpp and .txt. A fresh, uncorrupt copy of the original .txt that works in another i/o program I wrote.

http://www.filedropper.com/main_7

http://www.filedropper.com/file_1032
Topic archived. No new replies allowed.