도서 관리프로그램을짜는데요...검색함수를 짜는데 ㅠ
한길찬
도서관리프로그램....검색함수좀 봐주세요 ㅠ제가 허접한 실력으로 도서관리프로그램을 짯는데요....다른건 다 괞찬은데.....이상하게..검색을할때....텍스트파일에서 잇는 내용을 한번 출력 하면 검색이 잘되는데요....이상하게....프로그램실행하자 마자 검색을 하면 이상하게 검색이 안되네요ㅠ 좀도와주세요 ㅠ질문 내용 : #include stdio.h
#include string.h
#define max 100
struct book_struct
{
char name[20];
char writer[20];
int year;
char pu[20];
}book[max];
int top=0;
void input(void); //도서입력 함수
void output(void); //도서출력 함수
void search(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);
if(key==1)
{
input();
}else if(key==2)
{
output();
}
else if(key==3)
{
search();
}
else if(key==4)
{
printf(*************************종료************************\n);
}
else if(key==5)
{
printf(*************************종료************************\n);
return 0;
}
else
{
printf(잘못된입력 입니다\n);
}
}
}
void input(void)
{
file * file = fopen(libray.txt, at);
printf(추가 하실 책 이름은: );
scanf(%s, book[top].name);
printf(추가 하실 책의 저자: );
scanf(%s, book[top].writer);
printf(추가 하실 책의 출판년도: );
scanf(%d, &book[top].year);
printf(추가 하실 책의 출판사: );
scanf(%s, book[top].pu);
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].pu);
fclose(file);
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].pu);
if(!*book[top].name) break;
}
for(i=0;itop;i++)
{
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].pu);
}fclose(file);
}
void search(void) //이상하게.....프로그램 실행해서 바로 검색 하면 검색이 안되네요.....한번 출력하고 하면되고또...
{
file* file =fopen(libray.txt, rt);
char name[20];
printf(검색 하실 책은 이름을 입력하시오: );
scanf(%s, name);
for(top=0; top200; top++)
{
if(strcmp(book[top].name,name)==0)
{
printf(도서명:%s\n, book[top].name);
printf(저자:%s\n, book[top].writer);
printf(출판년도:%d\n, book[top].year);
printf(출판사:%s\n, book[top].pu);
}
}
fclose(file);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |
2698430 | 변수의 값이 저장이 않되네요;; (4) | 피네 | 2025-06-16 |
2698404 | C#을 배울려고 하는데 C나 C++을 알아야 하나요 ?? (1) | 신당 | 2025-06-16 |
2698342 | 프로그램 질문점녀 (4) | 데빌의눈물 | 2025-06-16 |
2698318 | 파일 입출력 질문입니다~ (2) | 꽃 | 2025-06-15 |
2698291 | 문자 출력 함수 : putchar, fputc에 관하여. | 으뜸 | 2025-06-15 |
2698261 | 씨언어 (1) | 마리 | 2025-06-15 |
2698212 | 구조체, 포인터가 같이 들어간 프로그램 소스코드 있으신분? (4) | 그림자 | 2025-06-14 |