Pointer is not being assigned


I was working on this little project for a class and I'm running into this problem. I ran ddd on this example and prev is set to null when it exits the while loop, causing a Segmentation Fault.

When I was running ddd, I noticed that temp is not null and the two "prev is nulln" print statements don't get tripped but the one outside the loop does.

Do you know what could be happening?

            printf("while loop.\n");
            if(pe->y > temp->y)
                printf("while - if reached.\n");
            }//end if statement

            prev = temp;
            if(prev == NULL)
                printf("prev is null1\n");
            temp = temp->next;
            if(prev == NULL)
                printf("prev is null2\n");
        }//end while loop
        if(prev == NULL)
            printf("prev is null3\n");
        prev->next = pe;//redit links so that node is added in.
        pe->next = temp;

Show source
| sorting   | C   | graph   | linked-list   2016-11-18 23:11 1 Answers

Answers to Pointer is not being assigned ( 1 )

  1. 2016-11-18 23:11

    if this holds during the first iteration of the loop:

        if(pe->y > temp->y)

    then you never initialize prev.

Leave a reply to - Pointer is not being assigned

◀ Go back