티스토리 뷰

도서관리 시스템 고도화(라이브러리 적용)

 

프로그램 설계한

고도화 개요

[1]도서를 키워드로 검색하여 결과를 출력하는 프로그램을 개발
[2]코드 데이터에서 출판연도별 책 목록 출력 기능
ex) 저자 , 가격, 판매수령, 도서명, 코드

memcmp

연도별 출력 : strtok 함수를 이용하여 '-'를 구분자로 잘라내기
코드 검증 : strcspn()함수를 이용하여 숫자와 '-'가 아닌 문자열이 있는지 검사
키워드 검색 : strstr()함수를 이용하여 검색
자료 도서명 char bookTitle
저자 char bookAuthor
가격 int bookPrice
판매수량 int bookSale
코드 char bookCode(xxxx-xxx)
자료구조 struct book {
    charbookTitle [50];
    charbookAuthor [20];
    intbookPrice;
    intbookSale;
    charbookCode [9];
};

코드 분석

선언부


#include 
#include 
typedef struct book{
    char bookTitle [50];
    char bookAuthor [20];
    intbookPrice;
    intbookSale;
    charbookCode [ 9];// xxxx
xxx 북코드
}BOOK;
int inBook (BOOK* , int);
void outBook (BOOK* , int);
void searchBook (BOOK* , int);

 

코드입력 검증


int inBook (BOOK* mb , int cnt)
{
    int number;
    while(1){
        printf("\n책코드 :");
        gets(mb [cnt] .bookCode);
        if (strlen mb [cnt] bookCode ) == 8
        {
            number = strcspn ( cnt bookCode , "0123456789-");"
            if (number==8 && number != 0)
                    break;
        }

 

연도별 출력


printf("\n 검색할 출판연도를 입력하세요 : ”);
gets(sKey);
printf("\n----------------------");
printf("n%10s %30s n”, “ 코 드 ”, 제 목");
for(i =0; i<cnt; i++)
{
    year = strtok mb [i] .bookCode,"-");
    if (!strcmp year,sKey))
    {
printf("\n%10s %30s”,mb[i].bookCode , mb[i].bookTitle);
        check++;
    }
}
if(check == 0)
{
    printf("\n 일치하는 책이 없습니다 . \n”);
}

 

키워드 검색


printf("\n 검색할 제목을 입력하세요 :");
gets( sTitle );
for(i=0;i<cnt; i++)
{
    if (strstr mb[i].bookTitle,sTitle )!=NULL)
    {
    printf("\n\n----------------------");
    printf("\n코 드 : %s n”, mb [i]. bookCode);
    printf("제 목 : %s n”, mb [i]. bookTitle);
    printf("저 자 : %s n”, mb [i]. bookAuthor);
    printf("가 격 : %d n”, mb [i]. bookPrice);
    printf("판매수량 : %d n”, mb [i]. bookSale);
    check++;
    }
}
if(check)
    {
        printf("\n------------------------");
        printf("\검색 건수 : %d\n”, check);
    }
    else
{
        printf("\n------------------------");
        printf("\n 일치하는 책이 없습니다 .\n”);
}

 

댓글
© 2018 webstoryboy