inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

saneum3님의 게시글

saneum3 saneum3

@hwman

수강평 작성수
1
평균평점
5.0

게시글 5

질문&답변

readbooks, readbook2 함수 구현

아넵 알림을 못봐서 답변이 늦었네요,,; 그리고 두번째 질문에 대한 답은 찾았습니다! #include #include #include #define SLEN 101 struct book { char name[SLEN]; char author[SLEN]; }; void print_books(const struct book* books, int n); void write_books(const char* filename, const struct book* books, int n); struct book* read_books(const char* filename, int* n); void read_book2(const char* filename, struct book** book_dptr, int* n); int main() { int temp; int n = 3; struct book* my_books = (struct book*)malloc(sizeof(struct book) * n); if (!my_books) { printf("Malloc failed"); exit(1); } my_books[0] = (struct book){ "The great gatsby","F. scott" }; my_books[1] = (struct book){ "Hamlet","William shakespere" }; my_books[2] = (struct book){ "The odysey","Homer" }; print_books(my_books, n); printf("\nwriting to a file.\n"); write_books("books.txt", my_books, n); free(my_books); n = 0; printf("Done.\n"); printf("\npress any key to read data from a file.\n\n"); temp = _getch(); //my_books = read_books("books.txt", &n); read_book2("books.txt", &my_books, &n); print_books(my_books, n); free(my_books); n = 0; return 0; } void print_books(const struct book* books, int n) { for (int i = 0; i name); fscanf(fp, "%[^\n]%*c", book_dptr[i]->author); } fclose(fp); }

좋아요수
0
댓글수
3
조회수
387

질문&답변

gets() warnings 이유

아하 그렇군요 구체적이고 친절한 답변 감사드립니다,,

좋아요수
0
댓글수
2
조회수
391

질문&답변

scanf()함수 반환값

질문자님, 답변자님 모두 감사드립니다. 고민 해결하고 가네요 히

좋아요수
2
댓글수
4
조회수
1205