Passing an array to a linked list
Hi, i am trying to use a linked list in my code but i am having some difficulties. The link is defined like that:
Code:
struct kword {
unsigned char *word;
struct kword *next;
};
I am trying to pass the data of a two dimensional array row by row onto this unsigned char *word, but i can't find a way to do it.
I copy the two dimensional array on to a one dimensional array:
Code:
char pattern_small[m];
for( i = 0; i < 5; i++)
pattern_small[i] = pattern[0][i];
i create a pointer to this 1d array:
Code:
char *test = pattern_small;
and i assign this pointer to the list:
Code:
struct kword *khead, *ktemp;
ktemp = ( struct kword * ) malloc ( sizeof ( struct kword ));
ktemp->word = test;
ktemp->next = khead;
khead = ktemp;
But this doesn't work.
pattern_small[0]-[5] holds the string "abcde". If i pass the string directly (ktemp->word = "abcde"; i get correct results instead of using the pointer.
I would appreciate for any ideas on this!!