디버그 에러???좀 고쳐주세여
길가온
질문 제목 : 수정좀요질문 내용 :
#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) );
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |
2694229 | 단순한 질문이요 (8) | 여름 | 2025-05-09 |
2694202 | 용돈을 가지고 할 수 있는 일을 여러가지로 출력하는 방법 좀 알려주세요! (2) | 미나 | 2025-05-09 |
2694145 | 화면깜빡임을 없애고 싶은데요... (1) | 어서와 | 2025-05-08 |
2694069 | unsigned 질문입니다. | 힘차 | 2025-05-07 |
2694012 | 전공 비전공자 개발자 (10) | 말글 | 2025-05-07 |
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |