형들 내가 구조체를 이용해서 성적입력받고 출력하는 프로그램을 만들었는데
컴파일 execute 다 되는데 프로그램 실행하면
Microsoft Visual C++ Debug Library
Debug Error!
Program: C:\\Document and Settings\\JJDO\\바탕화면\\JJ\\Cmodel\\run.exe
Module:
File: i386\\chkesp.c
Line: 42
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
이라고 오류가 뜨면서 튕기거든? 이게 호출규약이 틀려서 생기는 오류라는건 알겠는데
어딜고쳐야될지를 모르겠어ㅠ 시간남는 형들 좀 도와줘#include <stdio.h>
#include <stdlib.h> // malloc, free
#include <string.h> // strcpy
typedef enum {
false,
true
} bool;
typedef enum {
Sort_Average,
Sort_Name
} Sort;
typedef enum {
Sub_Korean,
Sub_English,
Sub_math
} subject;
typedef struct {
bool flag; // 값 입력 여부
char Name[32];
int Korean;
int English;
int Math;
int Total;
float Average;
} tStudent;
static char choice = 0;
static int position = 0;
static int arraysize = 1; // 1명을 초기치로 설정
static tStudent *tMap;
bool InputMenu(void)
{
choice = 0;
printf(\"\\n--------------Menu--------------\\n\");
printf(\"1. 새 학생 추가\\n\");
printf(\"2. 성적순으로 보기(평균)\\n\");
printf(\"3. 이름순으로 성적 출력(가나다)\\n\");
printf(\"4. 종료\\n\");
printf(\"--------------------------------\\n\");
fflush(stdin); // 버퍼 초기화. scanf에서 문자 입력시 무한 루프 방지
scanf(\"%d\", &choice);
//printf(\"입력 = %d\\n\", choice);
if(choice < 1 || choice > 4)
{
printf(\"\\n1~4 만 입력 가능합니다 다시 입력하세요\\n\\n\");
return true;
}
return false;
}
bool getScore(subject num)
{
char title[4];
int temp;
switch(num)
{
case Sub_Korean:
strcpy(title, \"국어\");
break;
case Sub_English:
strcpy(title, \"영어\");
break;
case Sub_math:
strcpy(title, \"수학\");
break;
default:
break;
}
printf(\"%s 점수를 입력하세요\\n\", title);
fflush(stdin);
scanf(\"%d\", &temp);
if(temp < 0 || temp > 100)
{
printf(\"\\n점수는 0~100 사이만 가능합니다.\\n\");
return true;
}
else
{
switch(num)
{
case Sub_Korean:
tMap[position].Korean = temp;
break;
case Sub_English:
tMap[position].English = temp;
break;
case Sub_math:
tMap[position].Math = temp;
break;
default:
break;
}
}
return false;
}
void addStudent(void)
{
bool misscore = true;
if(tMap[position].flag == true)
position++;
// 최대 학생수(초기 64)를 초과하면 구조체 공간을 1명씩 추가
printf(\"크기 = %d \\n\", arraysize);
if(position > (arraysize - 1))
{
arraysize++;
printf(\"학생 1명 추가(크기 = %d)\\n\", arraysize);
tMap = (tStudent*)realloc(tMap, sizeof(tStudent)*arraysize);
}
tMap[position].flag = true;
printf(\"이름을 입력하세요\\n\");
scanf(\"%s\", &tMap[position].Name);
while(misscore)
{
misscore = getScore(Sub_Korean);
}
misscore = !misscore;
while(misscore)
{
misscore = getScore(Sub_English);
}
misscore = !misscore;
while(misscore)
{
misscore = getScore(Sub_math);
}
tMap[position].Total = tMap[position].Korean + tMap[position].English + tMap[position].Math;
tMap[position].Average = (float)tMap[position].Total / 3;
}
void Sorting(Sort num)
{
int i, j;
tStudent *tTemp = (tStudent*)malloc(sizeof(tStudent));
for(i = 0; i < arraysize; i++)
{
for(j = i+1; j < arraysize; j++)
{
if(num == Sort_Average)
{
if(tMap[i].Average < tMap[j].Average)
{
*tTemp = tMap[i];
tMap[i] = tMap[j];
tMap[j] = *tTemp;
}
}
else
{
if(strcmp(tMap[i].Name, tMap[j].Name) > 0)
{
*tTemp = tMap[i];
tMap[i] = tMap[j];
tMap[j] = *tTemp;
}
}
}
}
printf(\" 이름 국어 영어 수학 평균 \\n\");
for(i = 0; i < arraysize; i++)
{
printf(\" %s %3d %3d %3d %3.2f\\n\", tMap[i].Name, tMap[i].Korean, tMap[i].English, tMap[i].Math, tMap[i].Average);
}
free(tTemp);
}
void main(void)
{
bool retry = true;
tMap = (tStudent*)malloc(sizeof(tStudent)*arraysize);
while(retry)
{
retry = InputMenu();
}
while(true)
{
switch(choice)
{
case 1: // 학생 추가
addStudent();
break;
case 2:
Sorting(Sort_Average);
break;
case 3:
Sorting(Sort_Name);
break;
default:
case 4:
return;
}
InputMenu();
}
free(tMap);
}
중간에 title[4]를 title[5]로 바꾸어야겟다
ㅁㄴㄹ