도서 관리프로그램을짜는데요...검색함수를 짜는데 ㅠ
한길찬
도서관리프로그램....검색함수좀 봐주세요 ㅠ제가 허접한 실력으로 도서관리프로그램을 짯는데요....다른건 다 괞찬은데.....이상하게..검색을할때....텍스트파일에서 잇는 내용을 한번 출력 하면 검색이 잘되는데요....이상하게....프로그램실행하자 마자 검색을 하면 이상하게 검색이 안되네요ㅠ 좀도와주세요 ㅠ질문 내용 : #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);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |
2694202 | 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) | 미나 | 2025-05-09 |
2694145 | 화면깜빡임을 없애고 싶은데요... (1) | 어서와 | 2025-05-08 |
2694069 | unsigned 질문입니다. | 힘차 | 2025-05-07 |
2694012 | 전공 비전공자 개발자 (10) | 말글 | 2025-05-07 |
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |