以下是我的单链表程序,我想在程序输出完以后逐个释放这些链表,不知怎么做 #include <stdio.h> #include <malloc.h> #include <conio.h>
struct person { char name[255]; struct person *node_next; };
struct person *node_head;
int main() { register int i; struct person *new_node; struct person *current_node; node_head=(struct person *)malloc(sizeof(struct person)); if(!node_head) { printf("Cannot allocate memory!\n"); return 0; } node_head->node_next=NULL; printf("Please input the name of leader: "); scanf("%s",node_head->name); printf("Please input ten staff name\n"); current_node=node_head; for(i=0;i<10;i++) { new_node=(struct person *)malloc(sizeof(struct person)); if(!new_node) { printf("Cannot allocate memory!\n"); return 0; } scanf("%s",new_node->name); new_node->node_next=NULL; current_node->node_next=new_node; current_node=new_node; } current_node=node_head; printf("\n\n"); while(current_node) { printf("%s\n",current_node->name); current_node=current_node->node_next; } getch(); return 1; }