jamesonang@gmail.com wrote:[color=blue]
> DATA * frstp ; // the frstp is the pointer to structure
> frstp = NULL ; // the fist pointer is null at the beginning
>
> // the you can create a new node like this
> DATA *cur;
> cur = (DATA *)malloc(sizeof(DATA)) ;
> cur->field1 =< input by user>
> cur->field2= < input by user>
>
> frstp->next = cur; // a data is added to list.[/color]
[color=blue]
> frstp = NULL ; // the fist pointer is null at the beginning[/color]
the first (head) pointer points to NULL
[color=blue]
> frstp->next = cur; // a data is added to list.[/color]
and now frstp's next memeber points to cur. The problem is that frstp
is NULL from the previous call. Can you still do
frstp->next=<something> since frstp is not allocated?
[color=blue]
>From what I've seen on the group so far, it seems that casting malloc[/color]
is a bad idea as it may hide the fact that you forgot to include
<stdlib.h>.
Also, read
http://cfaj.freeshell.org/google/ before posting from google
groups.