#include <stdio.h>
#include <string.h>
#define TABLE_SIZE 100
#define TITLE_SIZE 100
#define NAME_SIZE 50
#define LOCATION_SIZE 100
enum book_type { COMIC, SF, NONFICTION, CLASSIC }; // 열거형을 사용하여 도서 분류
char *genre_text[] = { "만화", "공상과학", "비소설", "고전" }; // 열거형에 대응되는 문자열
typedef struct book {
char title[TITLE_SIZE]; // 제목
char author[NAME_SIZE]; // 저자
char location[LOCATION_SIZE]; // 책의위치
enum book_type genre; // 장르
} BOOK;
int get_value(void);
void menu(void);
void add_record(BOOK library[], int count);
void print_record(BOOK library[], int count);
void search_record(BOOK library[], int count);
int main(void)
{
BOOK library[TABLE_SIZE];
int count = 0;
while(1)
{
menu(); // 메뉴를 출력한다.
switch(get_value())
{
case 1:
if( count >= TABLE_SIZE )
{
printf("더 이상의 추가가 불가능합니다\n");
break;
}
add_record(library, count);
count++;
break;
case 2:
print_record(library, count);
break;
case 3:
search_record(library, count);
break;
case 4:
return 0;
default:
printf("잘못된 선택입니다.\n");
break;
}
}
}
// 사용자로부터 값을 입력받는다.
int get_value()
{
int i;
printf("정수값을 입력하시오:");
scanf("%d", &i);
fflush(stdin); // 입력을 초기화하기 위하여 호출
return i;
}
// 화면에 메뉴를 출력한다.
void menu(void)
{
printf("=====================\n");
printf("1. 추가\n");
printf("2. 출력\n");
printf("3. 검색\n");
printf("4. 종료\n");
printf("=====================\n");
}
// 책을 라이브러리에 추가한다.
void add_record(BOOK library[], int count)
{
int type;
printf("제목: ");
gets(library[count].title);
printf("저자: ");
gets(library[count].author);
printf("위치: ");
gets(library[count].location);
printf("장르(0: 만화, 1: 공상과학, 2: 비소설, 3: 고전) ");
scanf("%d", &type);
if( type >= COMIC && type <= CLASSIC )
library[count].genre = type;
else
library[count].genre = COMIC;
}
// 라이브러리의 책을 출력한다.
void print_record(BOOK library[], int count)
{
int i;
for(i = 0; i < count; i++)
{
printf("제목: %s\n", library[i].title);
printf("저자: %s\n", library[i].author);
printf("위치: %s\n", library[i].location);
printf("장르: %s\n\n", genre_text[library[i].genre]);
}
}
// 라이브러리에서 책을 탐색한다.
void search_record(BOOK library[], int count)
{
int i;
char title[TITLE_SIZE];
printf("제목: ");
gets(title);
for(i = 0; i < count; i++)
{
if( strcmp(title, library[i].title) == 0 )
{
printf("저장된 위치는 %s\n", library[i].location);
return;
}
}
printf("찾는 책이 테이블에 없습니다.\n");
}
没有合适的资源?快使用搜索试试~ 我知道了~
C-Programming-Source.zip_visual c
共256个文件
c:254个
h:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 98 浏览量
2022-09-21
20:12:55
上传
评论
收藏 86KB ZIP 举报
温馨提示
C Programing Source for Students
资源推荐
资源详情
资源评论
收起资源包目录
C-Programming-Source.zip_visual c (256个子文件)
library.c 3KB
book3.c 2KB
fseek.c 1KB
score3.c 1KB
fp2.c 1KB
book2.c 1KB
binary_file.c 944B
bubble_sort1.c 929B
bubble_sort.c 886B
selection_sort.c 854B
union2.c 821B
binary_search.c 783B
get_max_min.c 769B
modify.c 741B
fcopy1.c 732B
dump.c 711B
fappend.c 711B
flag.c 707B
book1.c 702B
two_dimen_array.c 674B
average.c 643B
calc2.c 641B
search.c 640B
combination.c 636B
calendar.c 631B
line_para.c 622B
add2.c 617B
burger.c 598B
integer.c 592B
integer.c 592B
calc.c 590B
fp1.c 589B
str_cat.c 570B
enum2.c 567B
count_word.c 563B
array_of_struct.c 558B
dic.c 557B
strcmp.c 552B
st_pointer1.c 545B
char_probe.c 527B
exchange_rate.c 526B
pointer2.c 522B
nested_struct.c 515B
matrix.c 514B
vector.c 513B
power.c 512B
burger2.c 507B
seq_search.c 505B
realloc.c 500B
letter_game.c 500B
str_ncmp.c 490B
const1.c 489B
st_pointer.c 489B
point.c 481B
pf3.c 478B
sales.c 472B
slope.c 472B
memcmp.c 462B
dice.c 462B
compound_interest.c 461B
pointer_to_st.c 461B
typedef.c 461B
qsort.c 459B
average1.c 457B
strtok.c 456B
get_integer.c 450B
power.c 440B
student2.c 440B
hanoi_tower.c 438B
slow_power.c 437B
random.c 434B
malloc4.c 430B
malloc3.c 429B
charclass.c 428B
int_const.c 425B
fread.c 425B
p_array3.c 424B
memcpy.c 422B
pointer_arith1.c 418B
modulo.c 416B
grade.c 415B
swap1.c 413B
swap2.c 413B
arithmetic.c 410B
main.c 408B
days_in_month.c 407B
random.c 402B
malloc2.c 397B
average_sub.c 397B
incdec.c 396B
const12.c 395B
define1.c 395B
calloc.c 393B
fwrite.c 393B
sum_even.c 390B
if_else2.c 389B
copy_array.c 389B
frequency.c 386B
to_upper.c 386B
compute_sum.c 385B
共 256 条
- 1
- 2
- 3
资源评论
alvarocfc
- 粉丝: 112
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于C++的二叉排序树(免费提供源码)
- demo(1).zip
- 网页版扫雷image文件
- matlab+数据预处理+ARIMA预测+异常值+检测+适用于各种类型的数据集
- mubanyuanshizhan-0604-24
- Python旅游数据爬虫及可视化展示源码
- 基于MFC恶意PE,Android签名流检测系统框架 vs2022 + c/c++ + mfc + PE + APK
- 基于MFC恶意文件检测系统 框架 vs2022 + c/c++ + hook + PE + inject + 动态调试工具Imm
- 基于MFC恶意文件检测系统框架 vs2022 + c/c++ + hook + PE + inject + 动态调试工具Imm
- 八路抢答器电子工艺实习报告
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功