free함수 디버그 문제 답변 부탁드립니다..
다인
질문 제목 : free함수 디버그 문제밑에 코딩 보시면 빨강칠 한부분을 주석처리하면 디버그가 안뜨는걸로 봐서 프리함수에 문제가 있는듯 해요..질문 내용 :
#include stdio.h
#include stdlib.h
#include malloc.h
typedef struct
{
float kor; //국어
float eng; //영어
float mat; //수학
float sci; //과학
float soc; //사회
float sum; //합계
float ave; //평균
} subject;
typedef struct
{
char number[20]; //학번
char name[20]; //이름
subject score;
} student;
void menu(void)
{
printf(1. 학생 정보\n);
printf(2. 성적 입력\n);
printf(3. 성적 출력\n);
printf(4. 종료\n);
printf(--------);
}
void inputstudent(int i, student * sptr)
{
printf(%d번째 학생학번 : ,i+1);
scanf(%s,sptr-number);
printf(%d번째 학생이름 : ,i+1);
scanf(%s,sptr-name);
}
void inputscore(student * sptr)
{
printf(%s %s 국어점수 : ,sptr-number, sptr-name);
scanf(%f,&sptr-score.kor);
printf(%s %s 영어점수 : ,sptr-number, sptr-name);
scanf(%f,&sptr-score.eng);
printf(%s %s 수학점수 : ,sptr-number, sptr-name);
scanf(%f,&sptr-score.mat);
printf(%s %s 과학점수 : ,sptr-number, sptr-name);
scanf(%f,&sptr-score.sci);
printf(%s %s 사회점수 : ,sptr-number, sptr-name);
scanf(%f,&sptr-score.soc);
sptr-score.sum=sptr-score.kor+sptr-score.eng+sptr-score.mat+sptr-score.sci+sptr-score.soc;
sptr-score.ave=sptr-score.sum/5.0;
}
void outputscore(student * sptr)
{
printf(\t%s %s %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n, sptr-number, sptr-name, sptr-score.kor,
sptr-score.eng, sptr-score.mat, sptr-score.sci, sptr-score.soc, sptr-score.sum, sptr-score.ave);
}
int main(void)
{
int n, i, choice;
printf(\n====================성적관리프로그램====================\n\n\n);
printf(몇명의 성적을 관리하시겠습니까? : );
scanf(%d, &n);
student * stu = (student *)malloc(sizeof(char)*n);
for(choice=0; choice!=4; )
{
menu();
scanf(%d,&choice);
switch(choice)
{
case 1:
for(i=0; in; i++)
inputstudent(i, &stu[i]);
break;
case 2:
for(i=0; in; i++)
inputscore(&stu[i]);
break;
case 3:
printf(\t 학번 이름 국어 영어 수학 과학 사회 총점 평균\n);
for(i=0; in; i++)
outputscore(&stu[i]);
break;
case 4:
break;
default:
printf(잘못 입력하셨습니다.\n\n);
}
}
free(stu);
}
위에 그림이 뜨는 디버그 입니다..
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |