도서 관리프로그램을짜는데요...검색함수를 짜는데 ㅠ
한길찬
도서관리프로그램....검색함수좀 봐주세요 ㅠ제가 허접한 실력으로 도서관리프로그램을 짯는데요....다른건 다 괞찬은데.....이상하게..검색을할때....텍스트파일에서 잇는 내용을 한번 출력 하면 검색이 잘되는데요....이상하게....프로그램실행하자 마자 검색을 하면 이상하게 검색이 안되네요ㅠ 좀도와주세요 ㅠ질문 내용 : #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);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |