๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 11์žฅ Mini Project ๋ฌธ์ œ ํ’€์ด

by A Lim Han 2023. 1. 26.

# 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;
}