도서 관리프로그램을짜는데요...검색함수를 짜는데 ㅠ
한길찬
도서관리프로그램....검색함수좀 봐주세요 ㅠ제가 허접한 실력으로 도서관리프로그램을 짯는데요....다른건 다 괞찬은데.....이상하게..검색을할때....텍스트파일에서 잇는 내용을 한번 출력 하면 검색이 잘되는데요....이상하게....프로그램실행하자 마자 검색을 하면 이상하게 검색이 안되네요ㅠ 좀도와주세요 ㅠ질문 내용 : #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);
}
| 번호 | 제 목 | 글쓴이 | 날짜 |
|---|---|---|---|
| 2752142 | 더블 포인터 관련 최대최소값 구하기 (2) | 풀잎 | 2026-10-21 |
| 2752115 | c언어 이상한질문 (4) | 모드니 | 2026-10-21 |
| 2752085 | 문자열을 랜덤하게 출력해서 대체,삽입,삭제 횟수를 각가 표시하고 그걸 표 형태로 출력 | 슬아s | 2026-10-20 |
| 2752056 | 포인터 && 배열 질문요~ (2) | 해찬나래 | 2026-10-20 |
| 2752031 | x^n 구하는 코드 짜봤는데 값이 틀려요 ㅠㅠ | 세실 | 2026-10-20 |
| 2752000 | 나 정말 미치겠어요..ㅠㅜ (4) | 다이 | 2026-10-20 |
| 2751978 | 문자열 질문이요.. | 초시계 | 2026-10-19 |
| 2751945 | 숫자 맞추는 프로그램이요 ㅠㅠ (1) | 동은 | 2026-10-19 |
| 2751917 | C언어 이중 연결 관련 질문합니다. | 유우 | 2026-10-19 |
| 2751888 | return의 정확한 의미좀 알려주세요 (3) | 올해1살 | 2026-10-19 |
| 2751857 | 포인터 배열 (2) | 터큰 | 2026-10-18 |
| 2751831 | 연산자? 질문입니다 (2) | 진주 | 2026-10-18 |
| 2751800 | C언어 기초질문입니다.. (3) | 핫블랙 | 2026-10-18 |
| 2751739 | 파일 출력을 구조체로 받을 때, 파일의 끝을 판별하는 방법을 알려주세요. (2) | 얼 | 2026-10-17 |
| 2751715 | unresolved external symbol 에러... | 이룩 | 2026-10-17 |
| 2751686 | 변수 설정에 관한 질문입니다. | 꽃달 | 2026-10-17 |
| 2751655 | 자료구조 연습문제 | 한무릎 | 2026-10-17 |
| 2751631 | gets 함수 질문이요. (4) | 해늘 | 2026-10-16 |
| 2751553 | 퀵정렬 소스인데 주석좀 달아주세요 (1) | 싴흐한세여니 | 2026-10-16 |
| 2751528 | 저기 이거하는법좀 질문.. (2) | 가람슬기 | 2026-10-15 |
