am_abbas
March 7th, 2003, 02:40 AM
Hi Gurus,
I have created a linked list but dosent work. Can any one tell me what is worng, please.
Thanks and Regards,
Abbas
struct mass_list_s
{
double a_v_cg[4];
char *name;
struct mass_list_s *link;
}
add_to_list(struct mass_list_s **q,double av_cg[4],char nm[64])
{
struct mass_list_s *temp;
int i;
char buff[1000];
temp=*q;
if(*q==NULL)
{
*q=malloc(sizeof(struct mass_list_s));
temp=*q;
}
else
{
while(temp->link!=NULL)temp=temp->link;
temp->link=malloc(sizeof(struct mass_list_s));
temp=temp->link;
}
for(i=0;i<4;i++)temp->a_v_cg[i]=av_cg[i];
temp->name=nm;
temp->link=NULL;
}
display_list(struct mass_list_s *q)
{
while(q!=NULL)
{
printf("%l,%l,%l,%l",q->a_v_cg[0],q->a_v_cg[1],q->a_v_cg[2],q->a_v_cg[3]);
q=q->link;
}
}
I have created a linked list but dosent work. Can any one tell me what is worng, please.
Thanks and Regards,
Abbas
struct mass_list_s
{
double a_v_cg[4];
char *name;
struct mass_list_s *link;
}
add_to_list(struct mass_list_s **q,double av_cg[4],char nm[64])
{
struct mass_list_s *temp;
int i;
char buff[1000];
temp=*q;
if(*q==NULL)
{
*q=malloc(sizeof(struct mass_list_s));
temp=*q;
}
else
{
while(temp->link!=NULL)temp=temp->link;
temp->link=malloc(sizeof(struct mass_list_s));
temp=temp->link;
}
for(i=0;i<4;i++)temp->a_v_cg[i]=av_cg[i];
temp->name=nm;
temp->link=NULL;
}
display_list(struct mass_list_s *q)
{
while(q!=NULL)
{
printf("%l,%l,%l,%l",q->a_v_cg[0],q->a_v_cg[1],q->a_v_cg[2],q->a_v_cg[3]);
q=q->link;
}
}