hi,
i have something like this:
can anyone please post a piece of code that will iterate through a list construced of nodes, given a head element 'head'?Code:typedef struct node {
node *next;
char *data;
} node_t;
my code:
this works good, however always goes one element too far and thus prints a 'null' at the end of the list. i do not understand why.Code:int print_history(hashnode_t *node){
hashnode_t *tmp = node;
while (tmp != NULL) {
printf("%s ", tmp->data);
tmp = tmp->next;
}
return 0;
}
i malloc the next elements like this:
thanks for any explanations and help.Code:current->next = (hashnode_t *) malloc(sizeof(hashnode_t)); //create next
felix