saneum3
@hwman
Reviews Written
1
Average Rating
5.0
Posts
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
- 351
Q&A
realloc() ํจ์ ์ง๋ฌธ์ ๋๋ค.
์ ๊ฐ์ฌํฉ๋๋ค,, ์ดํด๋์์ต๋๋ค.
- 0
- 2
- 259
Q&A
gets() warnings ์ด์
์ํ ๊ทธ๋ ๊ตฐ์ ๊ตฌ์ฒด์ ์ด๊ณ ์น์ ํ ๋ต๋ณ ๊ฐ์ฌ๋๋ฆฝ๋๋ค,,
- 0
- 2
- 363
Q&A
์ค๋ฅ๊ฐ ์ ์๊ธฐ๋์ง ๋ํต ๋ชจ๋ฅด๊ฒ ์ด์ใ ใ
์,, ๊น๋ํ๊ณ ์น์ ํ ๋ต๋ณ ์ ๋ง ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ์ ํํ ์ดํด ๋์์ด์^^
- 0
- 2
- 254
Q&A
scanf()ํจ์ ๋ฐํ๊ฐ
์ง๋ฌธ์๋, ๋ต๋ณ์๋ ๋ชจ๋ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๊ณ ๋ฏผ ํด๊ฒฐํ๊ณ ๊ฐ๋ค์ ํ
- 2
- 4
- 1.1K




