반응형
저장하기
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); }
반응형
'→ 개발 > C' 카테고리의 다른 글
[C] STRCMP (0) | 2010.08.16 |
---|