ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [C] 파일 입출력
    1.개발/5.C 2010. 8. 16. 10:17
    저장하기

    void save(bm *book[])
    {
     FILE *fp;
     int i=0;
     int len;
    
     fp = fopen("input.txt", "w");
    
     if(fp == NULL)
     {
      printf("error");
      return;
     }
    // fprintf(fp, "%d ", a);
     for(i=0;ibookname)+1;
      fprintf(fp, "%d ", len);
      fprintf(fp, "%s ", book[i]->bookname);
      len = strlen(book[i]->writer)+1;
      fprintf(fp, "%d ", len);
      fprintf(fp, "%s ", book[i]->writer);
      fprintf(fp, "%d\n", book[i]->price);
     }
     fclose(fp);
    }
    
    불러오기


    void load(bm *book[])
    {
     FILE *fp;
     char temp[50];
     int i=0;
     int len;
    
     fp = fopen("input.txt", "r");
    
     if(fp == NULL)
     {
      printf("로드 실패\n");
      return;
     }
     fscanf(fp, "%d", &a);
     
     for(i=0;ibookname[50] = (char*)malloc(len+1);  
      fscanf(fp, "%s ", temp);
      strcpy(book[i]->bookname, temp);
      fscanf(fp, "%d ", &len);
      book[i]->writer[20] = (char*)malloc(len+1);  
      fscanf(fp, "%s ", temp);
      strcpy(book[i]->writer, temp);  
      fscanf(fp, "%d\n", &book[i]->price);
     }
     fclose(fp);
    }
    

    '1.개발 > 5.C' 카테고리의 다른 글

    [C] STRCMP  (0) 2010.08.16
    [C] 파일 입출력  (0) 2010.08.16

    댓글 0

Designed by Tistory.