# 11์ฅ Mini Project ๋ฌธ์ ํ์ด
451p_Mini Project)
#include <stdio.h>
#include <string.h>
struct Lib {
int number;
char writer[100];
char title[100];
};
int main()
{
int num = 0;
int how_many_books = 2;
char writer_search[100];
char title_search[100];
struct Lib book[200];
book[0].number = 1;
strcpy_s(book[0].writer, 20, "Mina");
strcpy_s(book[0].title, 20, "Life of lion");
book[1].number = 2;
strcpy_s(book[1].writer, 20, "David");
strcpy_s(book[1].title, 20, "Flower World");
while (1)
{
int book_number = 0;
int new_book_number = 0;
printf("\n=================================\n");
printf("1. ๋์ ๋ฒํธ๋ก ์ฑ
์ฐพ๊ธฐ\n");
printf("2. ์ ์ ์ด๋ฆ์ผ๋ก ์ฑ
์ฐพ๊ธฐ\n");
printf("3. ์ ๋ชฉ์ผ๋ก ์ฑ
์ฐพ๊ธฐ\n");
printf("4. ์๋ก์ด ์ฑ
์ถ๊ฐ\n");
printf("5. ๋์๊ด์ด ์์ฅํ ๋์์ ์ ํ์\n");
printf("6. ํด์ฅ\n");
printf("=================================\n");
printf("๋ฉ๋ด ์ค ํ๋๋ฅผ ์ ํํ์์ค: ");
scanf_s("%d", &num);
if (num == 1) //๋์ ๋ฒํธ๋ก ๋์ ์ฐพ๊ธฐ
{
printf("๋์ ๋ฒํธ๋ฅผ ์
๋ ฅํ์์ค: ");
scanf_s("%d", &book_number);
printf("๋์ ๋ฒํธ: %d ์ ์: %s ์ ๋ชฉ: %s\n", book[book_number-1].number, book[book_number-1].writer, book[book_number-1].title);
}
else if (num == 2) //์ ์ ์ด๋ฆ์ผ๋ก ๋์ ์ฐพ๊ธฐ
{
printf("์ ์ ์ด๋ฆ์ ์
๋ ฅํ์์ค: ");
rewind(stdin); //gets_s ์
๋ ฅ์ด ๋ฌด์๋ ๋ ์ถ๊ฐ
gets_s(writer_search, 100);
for (int i = 0; i < how_many_books; i++)
{
if (strcmp(book[i].writer, writer_search) == 0)
{
printf("๋์ ๋ฒํธ: %d ์ ์: %s ์ ๋ชฉ: %s\n", book[i].number, book[i].writer, book[i].title);
}
}
}
else if (num == 3) //์ ๋ชฉ์ผ๋ก ๋์ ์ฐพ๊ธฐ
{
printf("๋์ ์ด๋ฆ์ ์
๋ ฅํ์์ค: ");
rewind(stdin); //gets_s ์
๋ ฅ์ด ๋ฌด์๋ ๋ ์ถ๊ฐ
gets_s(title_search, 100);
for (int i = 0; i < how_many_books; i++)
{
if (strcmp(book[i].title, title_search) == 0)
{
printf("๋์ ๋ฒํธ: %d ์ ์: %s ์ ๋ชฉ: %s\n", book[i].number, book[i].writer, book[i].title);
}
}
}
else if (num == 4) //์๋ก์ด ๋์ ์ถ๊ฐ
{
int k = 0;
book[how_many_books].number = how_many_books + 1;
rewind(stdin); //gets_s ์
๋ ฅ์ด ๋ฌด์๋ ๋ ์ถ๊ฐ
printf("๋์ ์ ์๋ฅผ ์
๋ ฅํ์์ค: ");
gets_s(book[how_many_books].writer, 100);
rewind(stdin); //gets_s ์
๋ ฅ์ด ๋ฌด์๋ ๋ ์ถ๊ฐ
printf("๋์ ์ ๋ชฉ์ ์
๋ ฅํ์์ค: ");
gets_s(book[how_many_books].title, 100);
how_many_books++;
}
else if (num == 5) //๋์๊ด์ด ์์ฅํ ๋์ ์ ํ์
{
printf("ํ์ฌ ๋์๊ด์ด ์์ฅํ ๋์ ์๋ %d๊ฐ ์
๋๋ค.\n", how_many_books);
}
else
{
printf("์๋
ํ ๊ฐ์ญ์์ค.\n");
break;
}
}
return 0;
}