Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > problem with feof ?

Thread Tools

problem with feof ?

Les Cargill
Posts: n/a
Reply With Quote
James Kuyper
Posts: n/a
On 01/28/2013 11:58 PM, (E-Mail Removed) wrote:
> 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;
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.

> On Monday, January 28, 2013 10:23:35 PM UTC-6, Barry Schwarz wrote:
>> On Mon, 28 Jan 2013 17:48:05 -0800 (PST), (E-Mail Removed) wrote:
>>> Ben,

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 news server which is free. I'm quite happy with both,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
a problem when using int feof(FILE *fp); kindrain C Programming 22 07-13-2008 02:40 PM
A question about fscanf and feof ! ehui928 C Programming 7 11-07-2006 01:48 AM
question about gets() and feof(). C Programming 3 09-16-2005 05:36 PM
feof Joriveek C Programming 8 09-14-2005 06:21 PM
feof usage Mantorok Redgormor C Programming 28 09-29-2003 04:10 AM