I am working on a linked list library and here is a function I wrote:
/**
* go through a linked list and perform function func for every node of the
* linked list
*
* func is a function pointer to the function you would to apply on the node.
* it should return 0 if it is successful and non-zero value otherwise.
*/
void traverse_list(linkedlist * ll, int (* func)(void * args)){
node * temp;
temp = ll->head;
while( temp != NULL ){
if((* func)(temp->val))
fprintf(stderr,"Error processing value!\n");
temp = temp->next;
}
}
My question is simple, I tried something like travers_list(testlinkedlist,printf)
but it just cannot work(printf not printing anything out), what I am doing wrong? Can I do it at all, if I can, how?