블로그 이미지
송시혁

calendar

1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Notice

Tag

Recent Post

Recent Comment

Recent Trackback

Archive

#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);
  }
}    
  
    
    







  

posted by 송시혁