저기 제가 도서관리 프로그램을 짜는데요 ㅠ 도움좀주세요
마중물
아래에 빨간 글씨로 쓴부분 확인점 부탁드립니다ㅠㅠ질문 내용 : #include stdio.h
#include string.h
#include stdlib.h
#define max 100
struct book_struct
{
char name[20];
char writer[20];
int year;
char company[20];
}book[max];
int top=0;
void input(void); //도서입력 함수
void output(void); //도서출력 함수
void search(void); //도서검색 함수
void revise(void);//도서수정 함수
void del(void);//도서삭제 함수
int main(void)
{
while(1)
{
int key;
printf(***************수원대 도서관리 프로그램**************\n);
printf( 1.도서추가 \n);
printf( 2.도서출력 \n);
printf( 3.도서검색 \n);
printf( 4.도서수정 \n);
printf( 5.종료 \n);
printf(***************해당번호를 입력 하십시오**************\n);
printf(입력란-);
scanf(%d,&key);
fflush(stdin);
if(key==1)
{
input();
}
else if(key==2)
{
output();
}
else if(key==3)
{
search();
}
else if(key==4)
{
revise();
}
else if(key==6)
{
del();
}
else if(key==5)
{
printf(*************************종료************************\n);
printf(********************안녕히 가세요^^******************\n);
return 0;
}
else
{
printf(잘못된입력 입니다\n);
}
}
system(cls);
}
void input(void)
{
file * file = fopen(libray.txt, at);
printf(추가 하실 책 이름은: );
gets(book[top].name);
printf(추가 하실 책의 저자: );
gets(book[top].writer);
printf(추가 하실 책의 출판년도: );
scanf(%d, &book[top].year);
fflush(stdin);
printf(추가 하실 책의 출판사: );
gets(book[top].company);
fprintf(file, %s\n, book[top].name);
fprintf(file, %s\n, book[top].writer);
fprintf(file, %d\n, book[top].year);
fprintf(file, %s\n, book[top].company);fclose(file);
printf(*************도서목록에 추가 되었습니다^^************\n);
printf(\n);
}
void output(void)
{
file* file =fopen(libray.txt, rt);
int i=0;
for(top=0;top20;top++)
{
fscanf(file, %s\n,book[top].name);
fscanf(file, %s\n,book[top].writer);
fscanf(file, %d\n,&book[top].year);
fscanf(file, %s\n,book[top].company);
if(!*book[top].name) break;
}
printf(*******************현재 도서 목록 *******************\n);
for(i=0;itop;i++)
{
printf(도서명:%s\n, book[i].name);
printf(저자:%s\n, book[i].writer);
printf(출판년도:%d\n, book[i].year);
printf(출판사:%s\n, book[i].company);
printf(*****************************************************\n);
}
fclose(file);
}
void search(void)
{
file* file =fopen(libray.txt, rt);
int count=0;
int i;
char name[20];
char wr;char writer[20];
int year;
char company[20];
for(top=0;top200;top++)
{
fscanf(file, %s\n,book[top].name);
fscanf(file, %s\n,book[top].writer);
fscanf(file, %d\n,&book[top].year);
fscanf(file, %s\n,book[top].company);
if(!*book[top].name) break;
}
printf(무엇으로 검색 하시겠습니까?\n);
printf(1.도서명 2.저자 3.출판년도 4.출판사\n);
printf(입력란-);
scanf(%d,&i);
system(cls);
switch(i)
{
case 1:
printf(검색 하실 책은 이름을 입력하시오: );
scanf(%s, name);
system(cls);
for(top=0; top200; top++)
{
if(strcmp(book[top].name,name)==0)
{
printf(**************검색 하신 책의 정보 입니다*************\n);
printf(도서명:%s\n, book[top].name);
printf(저자:%s\n, book[top].writer);
printf(출판년도:%d\n, book[top].year);
printf(출판사:%s\n, book[top].company);
}
}
break;
case 2:
printf(검색 하실 저자를 입력하시오: );
scanf(%s, writer);
system(cls);
for(top=0; top200; top++)
{
if(strcmp(book[top].writer,writer)==0)
{
printf(**************검색 하신 책의 정보 입니다*************\n);
printf(도서명:%s\n, book[top].name);
printf(저자:%s\n, book[top].writer);
printf(출판년도:%d\n, book[top].year);
printf(출판사:%s\n, book[top].company);
}
}
break;
case 3:
printf(검색 하실 출판년도 입력하시오: );
count=scanf(%d, &year);
fflush(stdin);
system(cls);
if(count==1)
{
for(top=0; top200; top++)
{
if(book[top].year==year)
{
printf(**************검색 하신 책의 정보 입니다*************\n);
printf(도서명:%s\n, book[top].name);
printf(저자:%s\n, book[top].writer);
printf(출판년도:%d\n, book[top].year);
printf(출판사:%s\n, book[top].company);
}
}
}
else
{
printf(잘못입력하셨습니다\n);
}
break;
case 4:
printf(검색 하실 출판사를 입력하시오: );
scanf(%s,company );
system(cls);
for(top=0; top200; top++)
{
if(strcmp(book[top].company,company)==0)
{
printf(**************검색 하신 책의 정보 입니다*************\n);
printf(도서명:%s\n, book[top].name);
printf(저자:%s\n, book[top].writer);
printf(출판년도:%d\n, book[top].year);
printf(출판사:%s\n, book[top].company);
}
}
break;
default:
printf(********************해당 번호가 없습니다*******************\n);
}
fclose(file);
}
void revise()
{
int n,i,k;
char name[20];
char ch[20];
int ch_year;
file* file = fopen(libray.txt, rt);
for(top=0;top200;top++)
{
fscanf(file, %s\n,book[top].name);
fscanf(file, %s\n,book[top].writer);
fscanf(file, %d\n,&book[top].year);
fscanf(file, %s\n,book[top].company);
if(!*book[top].name) break;
}
fclose(file);
printf(수정하실 책의 이름을 입력하시오: );
fflush(stdin);
gets(name);
for(i=0; itop; i++){
if(strcmp(book[i].name, name)==0){
printf(*************수정 하실 책의 정보 입니다*************\n);
printf(도서명:%s\n, book[i].name);
printf(저자:%s\n, book[i].writer);
printf(출판년도:%d\n, book[i].year);
printf(출판사:%s\n, book[i].company);
printf(*****************************************************\n);
while(1)
{
printf(무엇을 수정 하시겠습니까?\n);
printf(1.도서명 2.저자 3.출판년도 4.출판사5.수정종료\n);
printf(입력란- );
scanf(%d,&n);
system(cls);switch(n)
{
case 1:
printf(수정하실 도서명를 입력하시오:);
scanf(%s,ch);
strcpy(book[i].name, ch);
printf(***************도서명이 수정되었습니다***************\n);
printf(\n);
file = fopen(libray.txt, wt);
for(k=0; ktop; k++){
fprintf(file, %s\n, book[k].name);
fprintf(file, %s\n, book[k].writer);
fprintf(file, %d\n, book[k].year);
fprintf(file, %s\n, book[k].company);
}
break;
case 2:
printf(수정하실 저자를 입력하시오:);
scanf(%s,ch);
strcpy(book[i].writer,ch);
printf(****************저자가 수정 되었습니다***************\n);
printf(\n);
file=fopen(libray.txt, wt);
for(k=0; ktop; k++){
fprintf(file, %s\n, book[k].name);
fprintf(file, %s\n, book[k].writer);
fprintf(file, %d\n, book[k].year);
fprintf(file, %s\n, book[k].company);
}
break;
case 3:
printf(수정하실 출판년도를 입력하시오:);
scanf(%d,&ch_year);
system(cls);
book[i].year=ch_year;
printf(**************출판년도가 수정 되었습니다**************\n);
printf(\n);
file=fopen(libray.txt, wt);
for(k=0; ktop; k++){
fprintf(file, %s\n, book[k].name);
fprintf(file, %s\n, book[k].writer);
fprintf(file, %d\n, book[k].year);
fprintf(file, %s\n, book[k].company);
}
break;
case 4:
printf(수정하실 출판사를 입력하시오:);
scanf(%s,ch);
system(cls);
strcpy(book[i].company,ch);
printf(****************출판사가 수정 되었습니다***************\n);
printf(\n);
file=fopen(libray.txt, wt);brwt);
for(k=0; ktop; k++){
fprintf(file, %s\n, book[k].name);
fprintf(file, %s\n, book[k].writer);
fprintf(file, %d\n, book[k].year);
fprintf(file, %s\n, book[k].company);
}
break;
/*case 5:
return 0;*/
default:
printf(수정을 종료 하겠습니다\n);
}
}
}
}
fclose(file);
}
void del()////////////////////////////여기함수요
{
int i;
char name[20];
file* file = fopen(libray.txt, rt);
for(top=0;top200;top++)
{
fscanf(file, %s\n,book[top].name);
fscanf(file, %s\n,book[top].writer);
fscanf(file, %d\n,&book[top].year);
fscanf(file, %s\n,book[top].company);
if(!*book[top].name) break;
}
fclose(file);
printf(삭제 하실 도서명을 입력하세요:);
scanf(%s,name);
for(i=0; i200; top++)
{
if(strcmp(book[i].name,name)==0)
{
book[i]=book[i+1];//////////////////이부분이 실행이안되네요 ㅠ 구조체에 그다음 구조체를 넣는다는건 안되나요
}입렵한 책의 이름과 일치하는 구조체에 그다음 구조체로 넣어서 삭제하는
} 방법을 쓸려고 했는데...안되는 방법인가요?ㅠㅠ 어떤방식으로 써야 좋을
printf(삭제가 완료 되었습니다);까요? 수정이나 조언좀 부탁드릴게요
file=fopen(libray.txt, wt);
for(i=0; itop; i++){
fprintf(file, %s\n, book[i].name);
fprintf(file, %s\n, book[i].writer);
fprintf(file, %d\n, book[i].year);
fprintf(file, %s\n, book[i].company);
}
fclose(file);
}