공부하시는대에 도움이 됐으면 좋겠습니다.
답안코드 확인해주세요!
더보기
#include <stdio.h>
#include <string.h>
#define TITLE_SIZE 50
#define NAME_SIZE 50
#define PUBLISHER_SIZE 50
typedef struct BOOK {
char title[TITLE_SIZE];
char author[NAME_SIZE];
char publisher[PUBLISHER_SIZE];
}
BOOK;
void add_record(BOOK library[], int count);
void menu();
int get_input();
void search_record(BOOK library[], int count);
void print_record(BOOK library[], int count);
int main(void) {
int num, count = 0;
BOOK library[30] = {
'\0'
}
;
while(1) {
menu();
num = get_input();
switch(num) {
case 1:
add_record(library, count);
count++;
continue;
case 2:
print_record(library, count);
continue;
case 3:
search_record(library, count);
continue;
case 4:
return -1;
}
return 0;
}
}
void add_record(BOOK library[], int count) {
int type;
fflush(stdin);
printf("도서의 이름:");
gets(library[count].title);
printf("저자:");
gets(library[count].author);
printf("출판사:");
gets(library[count].publisher);
}
void menu() {
printf("====================\n");
printf(" 1. 추가\n");
printf(" 2. 출력\n");
printf(" 3. 검색\n");
printf(" 4. 종료\n");
printf("====================\n");
}
int get_input() {
int num;
printf("정수값을 입력하시오 : ");
scanf("%d",&num);
return num;
}
void search_record(BOOK library[], int count) {
int i;
char title[TITLE_SIZE];
fflush(stdin);
printf("제목: ");
gets(title);
for (i = 0; i < count; i++) {
if(strcmp(title,library[i].title) == 0) {
printf("출판사는 %s\n",library[i].publisher);
return;
}
}
printf("찾는 책이 테이블에 없습니다.\n");
}
void print_record(BOOK library[], int count) {
int i;
fflush(stdin);
for (i = 0; i < count; i++) {
printf("제목 : %s\n",library[i].title);
printf("저자 : %s\n",library[i].author);
printf("출판사 : %s\n",library[i].publisher);
}
}
더 많은 C코드가 보고 싶다면?
'C언어' 카테고리의 다른 글
[C언어] 텍스트 파일에서 특정한 단어를 찾아서 다른 단어로 변경하여 출력 파일에 쓰는 프로그램을 작성하라. (0) | 2020.05.14 |
---|---|
[C언어] 파일에서 특정한 단어를 찾아서 파일 이름과 단어가 위치한 줄 번호를 출력하는 프로그램을 작성하시오 (0) | 2020.05.14 |
[C언어] 텍스트 파일을 읽어서 각 줄의 앞에 번호를 붙이는 프로그램을 작성하라. 줄 번호는 폭이 6이고 오른쪽 정렬되도록 하라. (0) | 2020.05.14 |
[C언어] 명령어 라인으로 주어진 2개의 텍스트 파일을 합하여 하나의 파일로 만드는 프로그램을 작성하라. (0) | 2020.05.14 |
[C언어] 임의의 실수 100개를 생성시킨 후에 텍스트 파일과 이진 파일로 저장하여 보고 그 크기를 비교하여 보라. (0) | 2020.05.14 |
댓글