problem with feof ?

J

James Kuyper

Hey Barry,

your comments are true - I've updated my code. However, I want to point out that your last comment related to traversing the list twice confused me a bit!
The variable *current will not be set as a result of the loop to the last node, rather, it will point to NULL!

So re-write the loop so it saves the end position:
last_node = current;
current = current->next;

Then use last_node, rather than wasting time with a second pass through
the linked list.
Simply setting the current->next = item; item->prev = current is not going to work. I believe the while condition should be changed in order to always point to the last item in the list.

That's not what he suggested.

I believe that the logic should be:

item->prev = current->prev;
if(current->prev)
current->prev->next = item;
item->next = current;
current->prev = item;

Changing current->next->prev is just wrong, and without it, there's no
need to check whether current->next is null.

I strongly recommend finding a proper newsreader and connect to a proper
news server, rather than using Google Groups - among other annoyances
associated with Google Groups, it is doubling the empty lines in quoted
material. I use Thunderbird as my news reader, and I've subscribed to
eternal-september.org news server which is free. I'm quite happy with both,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top