수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

간단한 도서관리프로그램만드는 중 질문있습니다...

다와

2023.04.01


질문 제목 :도서관리프로그램 -파일입출력기능문제 계속안되서 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

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2701754 strcmp,strcpy를 좀더 이해를 하기위해서 간단히 만들었는데... 말달리자 2025-07-17
2701724 배열초기화도중 이니셜라이저 가 너무 많다고 나오네요! (2) 라임나무 2025-07-16
2701697 6.0에서는 잘되던 프로그램이 2008에서는 잘안된답니다. 한번 아시는분 댓글부탁드립니다. (1) 빵순 2025-07-16
2701644 문자가 알파벳인지 검사하기(isalpha) 마음 2025-07-16
2701590 재가 C프로그래밍 아무것도 몰르는데요. (4) 대나무 2025-07-15
2701565 로그인 프로그램 개굴츼 2025-07-15
2701511 이거 오류 안나게 수정좀 부탁드릴께요 ㅠㅠ 돠주세요 ㅠㅠ 어리버리 2025-07-14
2701453 MFC문제점 해결방안좀알려주세요~~ 나샘 2025-07-14
2701429 자료형에 관한 질문 (5) 펴라 2025-07-14
2701377 훌로트형 변수를, 서식문자 %d로 읽기 vs 인트형 포인터로 참조하기 LetMeGo 2025-07-13
2701291 콘솔에서 종료시킬때 메시지를 안띄우려면 어떻게 해야하나요? (1) 세실 2025-07-12
2701262 씨언어 좀 봐주세요 아담 2025-07-12
2701211 토큰추출 겨루 2025-07-12
2701159 연산자문제 알려주세요 도1도캣 2025-07-11
2701130 중적분문제입니다. 적분구간에 변수가 들어갈순 없나요??ㅡㅜ 풀큰 2025-07-11
2701098 난수에 질문드립니다. 큰뫼 2025-07-11
2701070 또다른 시험문제 질문올립니다 채련 2025-07-10
2701042 뭐가 잘못된건지 잘 모르겠습니다.;; 지은 2025-07-10
2700986 뭐가 잘못된건지좀 봐주세요. 우주 2025-07-10
2700932 도와주세요 ㅠㅠ 모르겟어요 ㅠ 유희 2025-07-09
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com