수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • 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) );

번호 제 목 글쓴이 날짜
2700695 간단한 메모장 구현을 할려고 하는데요 (9) 늘솜 2025-07-07
2700668 c언어 질문입니다. 도와주세요~ (3) 가자 2025-07-07
2700639 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 두빛나래 2025-07-06
2700610 정말 기초적인 더하기,여백 문제 help 무슬 2025-07-06
2700562 함수포인터에서요 (7) 소심한여자 2025-07-06
2700530 전처리문 질문입니다. (1) 아놀드 2025-07-05
2700510 c언어를 어케하면 잘할수 있을까요.. 연연두 2025-07-05
2700484 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) 날위해 2025-07-05
2700426 인터넷 창 띄우는 질문이요 (1) 정훈 2025-07-04
2700400 원넓이를 계산이요 ㅜㅜ 천칭자리 2025-07-04
2700368 if에 관해서 질문이요... Orange 2025-07-04
2700339 이거 결과값이 왜이런건지.. (4) 그댸와나 2025-07-04
2700313 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) 크나 2025-07-03
2700287 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) 아련나래 2025-07-03
2700264 문자와 숫자 동시에 입력??? 글고운 2025-07-03
2700236 txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) 미국녀 2025-07-03
2700211 전위 연산자 (2) 어른처럼 2025-07-02
2700183 C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; 피스케스 2025-07-02
2700150 꼭좀 도와주세요ㅠㅠㅠ 호습다 2025-07-02
2700095 연산문제...질문... 오빤테앵겨 2025-07-01
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

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