On 6 Apr 2005 04:46:13 -0700, in comp.lang.c , "Roy J"
<> wrote:
>Hi all :
>I'm a newbie of c language , I confronted with a problem as below :
I think your logic for setting next is wrong. If you debug this,
you'll see it. Alternatively, draw a diagram of what each object
contains/points to, as you iterate from say n = 4 down to n=1.
Also, you need to set next to NULL for your last element, otherwise
theres no way to know you're at the end of the list.
> for (tmp = head; tmp->next = head; tmp++)
this is wrong. You need to move forward to the next node, and you
should keep going till you have a NULL next.
for(tmp=head; tmp!=NULL; tmp = tmp->next)
> printf("the node #%d\n",(*tmp).number);
the usual idiom for this is tmp->number
Also, note that you didn't free any of the malloc'ed pointers. You
should always do this as your OS may not otherwise recover the used
memory.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----