디버그 에러???좀 고쳐주세여
길가온
질문 제목 : 수정좀요질문 내용 :
#include stdio.h
#include string.h
#include stdlib.h
typedef struct info {
char name[30];
char tel[30];
} info;
enum choose { insert=1, delete, search, printall, exit };
int main()
{
int select;
int input;
int count_input=0;
int del;
int i;
char sc[30];
int sc_result;
int count=0;
int state;
char ch[30];
info *intro;
info *temp;
file * file = fopen(admin_tel.txt, rt);//file open ((reading
if( file==null ) {
printf(file open error! \n);
return 1;
} // if end
puts([history]);
for( ; feof(file) == 0 ; ) {
temp = (info*)malloc( sizeof(info*)*(count_input+1) );
if( count != 0)
temp = intro;
intro = (info*)malloc( sizeof(info*)*(count_input+1) );
if( count != 0)
intro = temp;
fscanf(file, %s, ch);
printf(%d번째 회원 / name : %s, count+1, ch);
strcpy( intro[count].name, ch);
fscanf(file, %s, ch);
printf(/ tel : %s \n, ch);
strcpy(intro[count].tel, ch);
count++;
count_input++;
}//for end
state = fclose(file);// file close ((reading
if( state != 0 ) {
printf(file close error! \n);
return 1;
}// if end
start :
puts(\n---------menu---------);
puts( 1. insert);
puts( 2. delete);
puts( 3. search);
puts( 4. print all);
puts( 5. exit);
printf(choose the item : );
scanf(%d, &select);
printf(\n);
system(cls);
switch(select)
{
case insert :
printf(how many people do you want to insert? : );
scanf(%d, &input);
count_input+= input;
if(count!=0) {
temp = (info*)malloc( sizeof(info*)*(count_input+2) );//malloc start.temp
temp = intro;
}//if end
intro = (info*)malloc( sizeof(info*)*(count_input+2) );//malloc start.intro
if(count!=0)
intro= temp;// if end
for( i=0 ; iinput ; count++, i++) {
printf([insert] \n);
printf(input name : );
scanf(%s, intro[count].name);
printf(input tel number : );
scanf(%s, intro[count].tel);
printf(-------- data inserted \n);
}// for end
break;
case delete :
printf([delete] \n);
printf(input a number for delete : );
scanf(%d, &del);
if(delcount_input) {
printf(you choose a wrong number \n);
break;
}// if end
for( ; delcount_input; del++ ) {
strcpy(intro[del-1].name, intro[del].name);
strcpy(intro[del-1].tel, intro[del].tel);
}
count_input--;
printf(-------- data deleted \n);
break;
case search :
printf([search] \n);
printf(for serching input a name or tel : );
scanf(%s, sc);
for( i=0; icount_input; i++ ) {
sc_result = strncmp(sc, intro[i].name, sizeof(sc) );
if( sc_result ==0 ) {
printf(name f(name : %s/tel : %s \n, intro[i].name, intro[i].tel);
goto start;
}//if end
sc_result = strncmp(sc, intro[i].tel, sizeof(sc) );
if( sc_result ==0 ) {
printf(name : %s/tel : %s \n, intro[i].name, intro[i].tel);
goto start;
}//if end
}// for end
printf(not founded \n);
break;
case printall :
printf([print all data] \n);
for( i=0; icount_input; i++ )
printf(%d번째 회원//name : %s /tel : %s \n, i+1, intro[i].name, intro[i].tel);// for end
break;
case exit :
file = fopen(admin_tel.txt, wt);//file open ((writing
if( file==null ) {
printf(file open error! \n);
return 1;
}// if end
for( i=0; icount_input; i++ ) {
fprintf(file, \n);
fputs(intro[i].name, file);
fprintf(file, );
fputs(intro[i].tel, file);
}// for end
state = fclose(file);// file close ((writing
if( state != 0 ) {
printf(file close error \n);
return 1;
}// if end
printf(have a nice day! \n);
free(intro);
free(temp); 이부분에서
return 0;//종료
}
goto start;//exit 제외 모든 case경우는 start로 돌아가서 반복시작
}
이런게 떠요 ㅠㅠ
개념이 부족해서 잘 모르겟어요...
-
반혈
텍스트파일에 내용이 있어도 안대는건 마찬가지에요..
-
쥬디시어스
안대는데요... 다른에러는 무슨 에러 말씀하시는거에요??
-
연블랙
아 하나 안올렸네요.
마지막쪽에 free하실때
if(NULL != intro )
free(intro);
if(NULL != temp )
free(temp); -
세찬
텍스트 파일에 내용이 없는 경우에는
메모리 할당을 하지 않아 (널 또는 쓰레기 값)을 가진 메모리 주소를
지우려고 하기 때문에 에러가 납니다.
INFO *intro = NULL;
INFO *temp = NULL;
해 주시면 우선 그 문제는 해결이 됩니다.
그런데 아마 다른 에러가 날 것 같아요.
살짝 보았는데.; -
김자영
텍스트파일 내용없음.....
-
드리
텍스트 파일 내용 좀~ 보여주세요
-
옆집언니
그래도 안대요 ㅠㅠ
-
난초
파일이 없어서 정확한 테스트는 안됩니다만..
아마 malloc 하실 때 사이즈를 잘못주셔서, 그 후에 영역 사용을 잘못한 문제로 보여집니다.
temp = (INFO*)malloc( sizeof(INFO*)*(count_input+2) );
를 아래와 같이 한번 바꾸어 보세요.
temp = (INFO*)malloc( sizeof(INFO)*(count_input+2) );
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |
2698644 | 1부터 n까지의 합을 구하는데 엄청긴숫자의 합을 구할때는 어떻게 해야하나요? (4) | 슬우 | 2025-06-18 |
2698616 | 다른 함수로 안넘어갑니다..;;; | 도1도캣 | 2025-06-18 |
2698587 | 배열하다 막혀서... (3) | WhiteCat | 2025-06-18 |
2698559 | 문자열을 비우는방법 (2) | 하늘 | 2025-06-18 |
2698528 | 착하고 친절한 선생씌구해염~ㅋㅋ (4) | 옆집언니야 | 2025-06-17 |
2698502 | 자료구조 큐 | 캔서 | 2025-06-17 |
2698477 | 실행화면 배경문의요 | 선아 | 2025-06-17 |
2698430 | 변수의 값이 저장이 않되네요;; (4) | 피네 | 2025-06-16 |
2698404 | C#을 배울려고 하는데 C나 C++을 알아야 하나요 ?? (1) | 신당 | 2025-06-16 |
2698342 | 프로그램 질문점녀 (4) | 데빌의눈물 | 2025-06-16 |
2698318 | 파일 입출력 질문입니다~ (2) | 꽃 | 2025-06-15 |
2698291 | 문자 출력 함수 : putchar, fputc에 관하여. | 으뜸 | 2025-06-15 |
2698261 | 씨언어 (1) | 마리 | 2025-06-15 |
2698212 | 구조체, 포인터가 같이 들어간 프로그램 소스코드 있으신분? (4) | 그림자 | 2025-06-14 |