#include <stdio.h> #include <process.h> #include <stdlib.h>
typedef struct node { char data; struct node *next; }NODE; void print_list (NODE *head); int main() { FILE *fp; NODE * temp = NULL, *list = NULL; char ch; if((fp= fopen("d10-5.txt", "r")) == NULL) { printf("file open error!"); exit(-1); } fscanf(fp, "%c", &ch); while(!feof (fp)) { temp=(NODE *) malloc(sizeof(NODE)); temp->data = ch; temp->next = list; list = temp; fscanf(fp, "%c", &ch); } fclose(fp);
temp = list; print_list(list); temp= list; while(temp != NULL) { //printf("%c ->", temp->data); list = temp; temp = temp->next; free(list); } //printf(" NULL\n");
return 0; }
void print_list (NODE *head) { if(head == NULL) { printf("NULL\n"); } else { printf("%c ==> ", head->data); print_list (head->next); } }
|