Thread: weird things with my linked list of queue

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    weird things with my linked list of queue

    ok, so here's the code first of all:

    Code:
    void push( TA_NODE * ndPtr)
    {
    
    int enter1,enter2;
    TA_NODE *talist = ( TA_NODE *) malloc ( sizeof(TA_NODE));
    
    enter1 = ndPtr->m_obj.m_enter_val1;
    enter2 = ndPtr->m_obj.m_enter_val2;
    
    ndPtr->taNextNode = taNodeList;
    ndPtr->taPrevNode = taNodeList;
    
    taNodeList = ndPtr;
    
    if( taNodeList->taPrevNode != 0 )
    	fprintf(stderr, "taprevnode %u\n",taNodeList->taPrevNode->m_type);
    
    talist = taNodeList;
    
    
    if ( ndPtr->m_type == TA_TYPE_EXIT )
    	{
    	while (talist->m_type != TA_TYPE_ENTER)
    		{
    		talist = talist->taNextNode;
    		}	
    	talist->m_obj.m_enter_val1 = enter1;
    	talist->m_obj.m_enter_val2 = enter2;
    	}	
    	
    	
    }
    Note that TA_NODE here is just a struct.. I have another test.c file that uses this push method everytime it needs to.. then I have a global variable called taNodeList.. Weird thing and rather strange is after that test.c finishes and I iterate my taNodeList just too see if all were pushed accordingly and it turns out that there's several which points no where.. What I did to iterate through this taNodeList is by printing the m_type properties that each TA_NODE list must and must have.. however sometimes several of them points to nowhere, (i,e it gives me a random number like 77123981, ...). I just don't get it why this is happening? I was iterating taNodeList just after test.c finishes, so there's no chance that there's somewhere else in the code that could modify it.. and also it's weird as because my program takes an input file.. and this doesn't happen for all input file given.. when I reduce/cut out several lines of the input file this doesn't happen... Can someone tell me what to do? I am starting to freak out to debug this code.. it's really weird

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Is it as badly indented in your editor, as it appears here?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    is there something wrong with the code?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Probably, but it's too awful to read, so I didn't bother looking.
    And since it hasn't improved overnight either, I'm still not interested enough to actually read the code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 01:13 PM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 07:47 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM