我正在研究一个链表库,这是我写的一个函数:
/**
* 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;
}
}
我的问题很简单,我尝试了类似 travers_list(testlinkedlist,printf)
但它无法工作(printf 没有打印任何东西),我做错了什么?我能做到吗,如果可以,怎么做?