user2963002
user2963002

Reputation: 11

Linked List in C, not linking properly

So I am trying to link a list together from user input their own file , but when I try printing it only prints the the first line, I believe the problem lies somewhere below in my code fragment, I think currp is not getting currp-next.

while ((fscanf( fpin, "'%[^']' %f %f %d" ,currp->name, &currp->cost,
                                        &currp->weight, &currp->dam) ==4 ))
        {
                prev = currp;
                currp->next = malloc(sizeof(item_t));
                assert(currp->next);
                currp = currp->next;
        }

        prev->next = NULL;
        free(currp);
        fclose(fpin);

        return (itb);

Upvotes: 0

Views: 68

Answers (1)

user2533527
user2533527

Reputation: 256

I guess currp does get next , but you just don't assign it . Just check it , Add a printf of currp->next as an integer It will represent it's address if address changes Then the problem is in assertion .

Upvotes: 1

Related Questions