inflearn logo
講義

講義

知識共有

saneum3さんの投稿

saneum3 saneum3

@hwman

レビュー投稿数
1
平均評価
5.0

投稿 5

Q&A

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
閲覧数
391

Q&A

gets() warnings 이유

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

いいね数
0
コメント数
2
閲覧数
399

Q&A

scanf()함수 반환값

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

いいね数
2
コメント数
4
閲覧数
1224