From: Jordan B. <jor...@me...> - 2011-05-09 15:45:12
|
Hey Everyone and good morning, I am in the process of creating a to do list console application and seems I have hit a wall so to speak. Below I have an exert from my actualy class. I have been trying to get this linked list working and so far it has failed. I did not know if it was the driver program that was failing, the class as a whole or this new code. I have excerted this code into another compiler and have tried to run it by itslef, Upon running it the console states it has encountered and error and closes. I have used the debugging mode on my compiler and it fails once it gets to the first line to create a new varalbe in the heap. I believe this is becasue all of my dynamic memory on my PC may be full as I get the "segmentation fault" error. I do not think that all the memory is in use by the other programs. If anything I should be able to make one Node in the memory. I just wanted to know before I change computers that it is in fact the memory being used and not some stupid mistake that I have made that is causing the problem. Any help would be fantastic! <code> #include <iostream> #include <cstdlib> #include <string> using namespace std; int main() { int numstep; struct step { int stepNum; string Instruction; }; struct Node { struct step steppy; Node *ptr_next_node; }; Node *Head; Node *Curr; Node *Last; numstep = 5; for( int i = 1; i <= numstep; i++) { (*Head).ptr_next_node = NULL; if((*Head).ptr_next_node == NULL) { Last = Head; Curr = Head; cout << " The " << i << "step, please enter the text for this setp and then press enter: "; cin >> (*Head).steppy.Instruction; (*Head).steppy.stepNum = i; (*Head).ptr_next_node = new Node; Curr = (*Head).ptr_next_node; } cout << "The " << i << " step, please enter the text for this step and then press enter: "; cin >> (*Curr).steppy.Instruction; (*Curr).steppy.stepNum = i; (*Curr).ptr_next_node = new Node; Last = Curr; Curr = (*Curr).ptr_next_node; } return 0;} </code> |