간단한 도서관리프로그램만드는 중 질문있습니다...
다와
질문 제목 :도서관리프로그램 -파일입출력기능문제 계속안되서 printf로 디버깅하는데
storedatafromfile()의 while문에서 걸려요
어디가 잘못된걸까요 아 모르겠어요답답해요진짜
한방에 속시원하게 알려주시면 감사하겠습니다.
질문 내용 : 아 아무리봐도 뭐가 잘못된건지 모르겠네요
계속 storedatafromfile()의 while문에서 걸리던데 대체 도통 이유를 모르겠네요
제발 알려주세요 아무리봐도모르겠어요( 첫번째실행하고 두번째 실행할떄 에러발생 아놬 돌아버리겠네요;;; )
소스 올립니다.(2개 헤더파일과 3개의파일)
메인소스.
#includestdio.h
#includestdlib.h
#includestring.h
#includelinkedlist.h
#includeshow.h
enum{input=1,show,search,remove,change,quit};
int main ( void )
{
listnode *l=initlist();
int num=0;
node * n;
printf(debug1);
loaddatafromfile(l);
printf(debug2);
while(1)
{
num=0;
menu();
scanf(%d,&num);
getchar();
switch(num)
{
case input:
n=(node*)malloc(sizeof(node));
memset(n, 0, sizeof(node));
fputs(*** input new book information ***\n,stdout);
fputs(title : ,stdout);
fgets(n-book.title, title-1, stdin);
n-book.title[strlen(n-book.title)-1]=0;
fputs(publish date: ,stdout);
fgets(n-book.publish_date, 15-1, stdin);
n-book.publish_date[strlen(n-book.publish_date)-1]=0;
fputs(author: ,stdout);
fgets(n-book.author, 30-1, stdin);
n-book.author[strlen(n-book.author)-1]=0;
fputs(price: ,stdout);
scanf(%d,&(n-book.price));
n-book.serinum=l-nodecount;
insert(l,n);
printf(data inserted);
getchar();
break;
case show:
&nbsbsp; show(l);
break;
case search:
n=search(l);
if(n!=null)print(n);
fputs(press enter key,stdout);
getchar();
break;
case remove:
remove(l);
storedatatofile(l);
break;
case change:
change(l);// not yet
storedatatofile(l);
break;
case quit:
storedatatofile(l);
free(l-head);
free(l-tail);
free(l);
break;
}
if(num==quit)
break;
}
printf(exit...\n);
return 0;
}linkedlist.c#includestdio.h
#includestdlib.h
#includestring.h
#includelinkedlist.h
#includeshow.h
//#includefcntl.h
listnode * initlist(void)
{
listnode * l=(listnode*)malloc(sizeof(listnode));
memset(l, 0, sizeof(listnode));
l-head=(node*)malloc(sizeof(node));
memset(&l-head-book, 0, sizeof(book));
l-tail=(node*)malloc(sizeof(node));
memset(&l-tail-book, 0, sizeof(book));
l-head-next=l-tail;
l-tail-prev=l-head;
l-head-prev=null;
l-tail-next=null;
return l;
}
int insert(listnode * l, node * n)
{
n-prev=l-tail-prev;
n-next=l-tail;
l-tail-prev-next=n;
n-next-prev=n;
l-nodecount+=1;
//printf(inserted!);
storedatatofile(l);
//clearreadbuffer();
return l-nodecount;
}
int show(listnode * l)
{
node * n =l-head-next;
for(n=l-head-next; n!=l-tail; n=n-next)
{
print(n);
}
fputs(press enter key\n,stdout);
getchar();
//clearreadbuffer();
return l-nodecount;
}
node * search(listnode * l)
{
node * n=l-head-next;
char srchname[30]={0,};
fgets(srchname, 30-1, stdin);
srchname[strlen(srchname)-1]=0;
while(n!=l-tail)
{
if(!strcmp(n-book.title, srchname))
{
fputs(found the book!\n,stdout);
return n;
}
n=n-next;
}
printf(.. cannot find the book.\n);
return null;
}
void remove(listnode * l)
{
node * n = l-head-next;
char deltitle[30]={0,};
fgets(deltitle, 29, stdin);
deltitle[strlen(deltitle)-1]=0;
while(n!=l-tail)
{
if(!strcmp(n-book.title, deltitle))
{
n-next-prev=n-prev;
n-prev-next=n-next;
free(n);
l-nodecount-=1;
printf(removed!);
getchar();
return;
}
n=n-next;
}
printf(the book does not exists.\n);
}
void change(listnode * l)
{
printf(change);
}
void loaddatafromfile(listnode * l)
{
file * fp=fopen(booklib1,rb);
node * n=(node*)malloc(sizeof(node));
if(fp==null)
{
printf(fopen() error!);
return;
}
while(!feof(fp))
{
fread(&(n-book),sizeof(book),1,fp);
insert(l, n);
printf(dd);
memset(&(n-book), 0, sizeof(book));
}
fclose(fp);
}
void storedatatofile(listnode * l)
{
file * fp=fopen(booklib1,wb);
node * n=l-head-next;
while(n!=l-tail)
{
fwrite(&(n-book), sizeof(book),1, fp);
n=n-next;
printf(debugging);
}
fclose(fp);
}show.c#includestdio.h
#includestdlib.h
#includestring.h
#includeshow.h
#includelinkedlist.h
void print(node * n)
{
printf(\n************ title: %s ************\n,n-book.title);
printf(publish_date : %s\n, n-book.publish_date);
printf(author : %s\n,n-book.author);
printf(price : %d(won)\n,n-book.price);
printf(serinum : %d\n,n-book.serinum);
printf(*********************************************\n);
}
void menu(void)
{
system(clear);
printf(**** menu ****\n);
printf(1. register book\n);
printf(2. show bookinfo\n);
printf(3. search bookinfo\n);
printf(4. remove bookinfo\n);
printf(5. change bookinfo\n);
printf(6. quit\n);
printf(choose no );
}
**헤더파일**linkedlist.h
#ifndef __linkedlist_h__
#define __linkedlist_h__
#define max 1000
#define title 50
#define name 30
typedef struct book_
{
char title[title]; // title
char publish_date[15]; //
char author[30];
int price;
int serinum;
}book;
typedef struct node
{
book book;
struct node * next;
struct node * prev;
}node;
typedef struct linkedlist
{
node * head;
node * tail;
int nodecount;
}listnode;
listnode * initlist(void);
int insert(listnode * l, node * n);
int show(listnode * l);
node * search(listnode * l);
void remove(listnode * l);
void change(listnode * l);
void loaddatafromfile(listnode * l);
void storedatatofile(listnode * l);
#endif
show.h
#ifndef _show_h__
#define _show_h__
#includelinkedlist.h
void print(node * n);
void menu(void);
#endif
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692401 | 유닉스안에서 C언어를 이용한 명함 만들기 입니다; 이해안가는 부분이있네요 | 2gether | 2025-04-22 |
2692374 | 고수님들 댓글 마니부탁해요!!! (2) | 엄지 | 2025-04-22 |
2692343 | scnaf에 자꾸 선언을 참조하라는데;; (8) | 도래 | 2025-04-22 |
2692282 | 도스상에서 생성된 exe파일에 press~ 뜨게 하기 (4) | 회사원 | 2025-04-21 |
2692256 | scanf("%*c"); ㅠㅠ 고수님들 | 거북이 | 2025-04-21 |
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
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 |