수다닷컴

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

디버그 에러???좀 고쳐주세여

길가온

2023.04.01

질문 제목 : 수정좀요질문 내용 :

#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로 돌아가서 반복시작
}

이런게 떠요 ㅠㅠ
개념이 부족해서 잘 모르겟어요...

신청하기





COMMENT

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

  • 반혈

    텍스트파일에 내용이 있어도 안대는건 마찬가지에요..

  • 쥬디시어스

    안대는데요... 다른에러는 무슨 에러 말씀하시는거에요??

  • 연블랙

    아 하나 안올렸네요.

    마지막쪽에 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
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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