Hi All
I' m a new member of Dani Web Community.my problem is with nested linked list implementation.when i insert second node in linked list, it always overwrites the first.
my declarations are as follows:

struct dataset
{
     int key ;
     char value[30];
     struct dataset *ptrdataset;

}*ptrd;
struct geometry
{
     char type[25] ;
     struct dataset *ptrdataset;
     struct geometry *ptrgeometry;

}*ptrg;
struct dxfdata
{
    struct geometry *ptrgeometry ;
    struct dxfdata *ptrdxfdata;

}*dxf,*temp2,*ptrdxfe;

//and I allocate memory as
dxf =(struct dxfdata *)malloc(sizeof(struct dxfdata));
dxf->ptrgeometry = (struct geometry *)malloc(sizeof(struct geometry));
temp = dxf; 
temp->ptrdxfdata = NULL;
temp->ptrgeometry = NULL;

ptrgtempe=(struct geometry *)malloc(sizeof(struct geometry));
ptrgtempe->ptrgeometry = NULL;
ptrgtempe->ptrdataset=NULL;
if(ptrdxfe->ptrgeometry == NULL)
{
    ptrdxfe->ptrgeometry = ptrgtempe;
    ptrge = ptrgtempe;
}
else
{
    while(ptrdxfe->ptrgeometry!=NULL)
        ptrdxfe->ptrgeometry = ptrdxfe->ptrgeometry->ptrgeometry;
    ptrdxfe->ptrgeometry = ptrgtempe;
}
addentitydataset(ptrdxfe,ptr);//ptrdxfe is a node of dxfdata and ptr 
             //is a node of of a single linked 
                                        // tnat is to added to the ptrdxfe
void addentitydataset(struct dxfdata *adddxf,struct sarray *sarray)
{

    struct dataset *ptrdump1;

    temp2= adddxf;


    ptrdump1 = (struct dataset *)malloc(sizeof(struct dataset));
    ptrdump1->key = atof(sarray->element);
    strcpy(ptrdump1->value , sarray->ptrsarray->element);
    ptrdump1->ptrdataset = NULL;
    if(temp2->ptrgeometry->ptrdataset == NULL)
    {
        ptrdxfe->ptrgeometry->ptrdataset=ptrdump1;
        ptrdtempe=ptrdxfe->ptrgeometry->ptrdataset;
        ptrgtempe=ptrdxfe->ptrgeometry;
    }
    else
    {
        while(temp2->ptrgeometry->ptrdataset!=NULL)
            temp2->ptrgeometry->ptrdataset=temp2->ptrgeometry->ptrdataset->ptrdataset;
        temp2->ptrgeometry->ptrdataset = ptrdump1;

    }
}

for example it works correctly for the first node addition in geometry(ptrgeometry) as ptrdxfe->ptrgeometry->ptrdataset=ptrdump1;
but for the second time it overwrites this node.
Please help me to sort out this problem.
sachin kumar
Email snipped

I think your main problem is here

//and I allocate memory as
dxf =(struct dxfdata *)malloc(sizeof(struct dxfdata));
dxf->ptrgeometry = (struct geometry *)malloc(sizeof(struct geometry));
temp = dxf;                      // here you are assigning dxf to temp;
temp->ptrdxfdata = NULL;  
temp->ptrgeometry = NULL;        // dxf->ptrgeometry is lost now
                                 // you are actually setting dxf->ptrgeometry to NULL

K.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.