From: Fernando L. <fer...@gm...> - 2011-05-09 22:17:11
|
Jordan, Head is a pointer, you use it before you assign anything to it, that is probably the cause of the "segmentation fault". It has to be assigned an actual address before you use it. Best regards, Fernando On 9 May 2011 12:44, Jordan Burnam <jor...@me...> wrote: > 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> > > > ------------------------------------------------------------------------------ > WhatsUp Gold - Download Free Network Management Software > The most intuitive, comprehensive, and cost-effective network > management toolset available today. Delivers lowest initial > acquisition cost and overall TCO of any competing solution. > http://p.sf.net/sfu/whatsupgold-sd > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > |