디버그 에러???좀 고쳐주세여
길가온
질문 제목 : 수정좀요질문 내용 :
#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) );
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |