Hello gurus!
I'm new in C and the following problem drives me crazy.
I am trying to implement a double linked list.
In main() I call the function as:
Code:
dlistInsertLast (&l, moveWhite[0], prevPos, nexPos);
in DEBUG mode I can see that prevPos and nexPos are pointers with value prevPos='a1' and nexPos='a7'
in function dlistInsertLast I assign the values in order to create my node etc...
Code:
void dlistInsertLast (dlist * lp, char p, char* ppos, char* npos)
/* Copy the data */
m->piece = p;
strncpy(m->prevPos, ppos, sizeof(m->prevPos)); //prevPos is a char array since it is not assignable we use strncpy
strncpy(m->nexPos, npos, sizeof(m->nexPos)); //to copy the data between the two
in DEBUG mode ppos='a1' and npos='a7'
now when I print my double linked list using function
Code:
void printDlist(dlist *lp)
i get the following
Previous Position : a1a7
Next Position : a7
which tells me that m->prevPos gets the value of both ppos and npos.
Any help about why that happens?