#include <stdio.h>
#include <stdlib.h>
#define MAX_SNUM_LNEN 10 //학번 최대 길이 정의
#define MIN_SNUM_LNEN 10 //학번 최소 길이 정의
#define MAX_NAME_LEN 5 //학생 이름 최대 길이 정의
#define MIN_NAME_LEN 1 //학생 이름 최소 길이 정의
typedef struct _Student Student;//Student 형식 이름 정의
struct _Student //_Student 구조체 정의
{
char snum[MAX_SNUM_LNEN]; ★
char snum[MIN_NAME_LEN];
char name[MAX_NAME_LEN]; ★
char name[MIN_NAME_LEN]; ★
char name[]; ★
int korean;
int math;
int english;
};
void Sort(Student *base, int n);
void View(Student *base, int n);
int main()
{
int n = 0;
Student *base = 0;
int i = 0;
printf("Enter a number of student : ");
scanf_s("%d", &n);//학생 수 입력
base = (Student *)calloc(n, sizeof(Student));//학생 수 * 학생 구조체 크기의 메모리 할당
for (i = 0; i < n; i++)//학생 정보 입력
{
printf("Enter a student info : snum, name, korean, math, english \n");
scanf_s("%s %s %d %d %d", base[i].name, MAX_NAME_LEN,
base[i].snum, MAX_SNUM_LNEN,
&base[i].korean, &base[i].math, &base[i].english);
}
Sort(base, n);//정렬
View(base, n);//출력
free(base);//동적 할당받은 메모리 해제
return 0;
}
void View(Student *base, int n)
{
int i = 0;
for (i = 0; i < n; i++)
{
printf("%-15s %-8s = = =\n",
base[i].snum, base[i].name, base[i].korean, base[i].math, base[i].english);
}
}
별표부분 에러 뜨는데 어케 고쳐야해 ㅜㅜ
배열들 이름이 같으니까 컴파일에서 에러나지요,, 심지어 배열도 런타임인건데 name[]게 만들어버리면..