도서관리 프로그램
중독된
질문 제목 : 도서관리 프로그램 도서 출력질문 내용 :
일단 도서 추가와 출력만 넣어논 상태인데
도서 추가를 하고서 출력을 하면 일단 1개만 추가했는데 출력을 하면
최근에 추가한 책이 복사되어서 2개가 출력이 되고
프로그램을 종료하면 데이터는 저장되었는데 리스트는 출력되지 않는데 어떻게 고쳐야할지 모르겠어요..#include stdio.h
#include stdlib.h
#include stdlib.h
#include windows.h
#include string.htypedef struct book
{
char title[100]; //책제목
char writer[100]; //저자명
char company[100]; //출판사
char num[100]; //일련번호
}book;
int main(void)
{
book book[100];
int menu;
int count=0;
int a;
int i; while(1) //무한반복
{
system(cls);
printf(=================================\n);
printf(= 도서 관리 프로그램 =\n);
printf(=================================\n\n);
printf(1.도서 추가\n); printf(2.도서 수정\n);
printf(3.도서 검색\n);
printf(4.도서 목록\n);
printf(5.프로그램 종료\n);
printf(=================================\n\n);
printf(=숫자만 입력해 주십시요!= \n\n);
printf(=원하는 메뉴번호를 입력하세요 : );
scanf(%d,&menu);
printf(\n);
if(menu==1)
{
file * file=fopen(data.txt,a+); //file *는 고수준파일입출력시 사용하는 구조체 주소를 보관.?
fflush(stdin); //버퍼에 남아 있는 데이터를 지워준다.
system(cls); // 화면 클린
printf(=================================\n);
printf( 도서 추가 항목\n);
printf(=================================\n\n);
printf(도서 제목 : );
gets(book[count].title); //gets 입력함수는 스페이스와 탭을 인식
fflush(stdin);
printf(저자명 : );
gets(book[count].writer);
fflush(stdin);
printf(출판사 : );
gets(book[count].company);
fflush(stdin);
printf(일련번호 : );
gets(book[count].num);
fflush(stdin);
printf(\n);
fprintf(file, %s\n, book[count].title);
fprintf(file, %s\n,book[count].writer);
fprintf(file, %s\n,book[count].company);
fprintf(file, %s\n\n,book[count].num);
count++;
fflush(stdin);
fclose(file);
continue;
}
else if (menu==2) //삭제
{
file * file =fopen(data.txt, r+);
fflush(stdin);
system(cls);
printf(=================================\n);
printf(수정할 책을 검색하세요\n);
printf(=================================\n\n);
continue;
}
else if (menu==3) //검색
{
file * file =fopen(data.txt, r+);
system(cls);
printf(=================================\n);
printf( 1.도서 제목 2.도서 일련번호\n);
printf(검색하려는 방법을 선택하세요 : );
scanf(%d,&a);
printf(\n);
printf(=================================\n\n);
fclose(file);
continue;
}
else if (menu==4) //목록
{
file * file =fopen(data.txt, r+);
system(cls);
printf(=================================\n);
printf( 도서목록 \n);
printf(=========================================\n\n);
if(file==null)
{
printf(도서 목록이 존재하지 않습니다.);
sleep(1000); //1초동안 프로그램을 멈춤
continue;
}
else
{ for(i=0; icount; i++)
{
fflush(stdin);
fscanf(file, %s %s %s %s \n,book[i].title,book[i].writer,book[i].company,book[i].num);
printf(도서 제목 : %s \n,book[i].title);
printf(작가 : %s \n,book[i].writer);
printf(출판사 : %s \n,book[i].company);
printf(일련번호 : %s \n,book[i].num);
printf(===========================\n);
fflush(stdin);
} }
sleep(1000);
fclose(file);
continue;
}
else if (menu==5) //종료
{
system(cls);
printf(=================================\n);
printf(\n프로그램을 종료하겠습니다.\n\n);
printf(=================================\n);
break; //break로 종료
}
else
{
system(cls);
printf(=================================\n);
printf(올바르지 않은 입력입니다.\n 다시 입력해주십시오.\n);
printf(=================================\n);
sleep(1000); //1초동안 프로그램을 멈춤
} }
}