我想在c中寫一個遞歸函數來打印一個鏈表。這是我的鏈表結構:在c中,使用if語句的結構項
typedef struct list_node{
char in_data;
struct list_node *next_item;
} list_node;
這裏是我的打印列表功能:
void print_list(list_node *head_of_list){
list_node *new_ptr = head_of_list.next_item;
if(new_ptr == '\0'){
printf(" %c", head_of_list->in_data);
}
else{
printf(" %c", head_of_list->in_data);
print_list(head_of_list->next_item);
}
return;
}
這裏是我不斷收到錯誤:
error: request for member ‘next_item’ in something not a structure or union
和錯誤說,這是對的與if(new_ptr ...語句一致。任何人都可以幫我消除這個錯誤嗎?謝謝
謝謝!這解決了它! – jani