비전공자인데 컴퓨터 혼자 배우고 있습니다 할때마다 막히네요..
#include <stdio.h>
#include <stdlib.h>
struct point
{
int midpoint;
int finpoint;
double ava;
};
struct student
{
char name[30];
int number;
struct point points;
};
typedef struct student stud;
stud* MakeStucture(stud *ppStd, int num);
void PrintStud(stud ppStd[], int num);
void FreeStructure(stud ppStd[]);
int main()
{
int num;
stud *ppStd;
printf("입력할 학생의 수를 입력하시오.\n");
scanf("%d", &num);
MakeStucture(&ppStd, num);
PrintStud(ppStd, num);
FreeStructure(ppStd);
return 0;
}
stud* MakeStucture(stud *ppStd, int num)
{
int i;
ppStd = (stud *)malloc(sizeof(stud)*num);
if (ppStd == NULL)
{
printf("동적 메모리 할당 실패\n");
exit(1);
}
printf("\n각 학생의 정보를 입력 : 이름 학번 중간 기말 \n");
for (i = 0; i < num; i++)
{
scanf("%s", (ppStd+i)->name);
scanf("%d", &((ppStd + i)->number));
scanf("%d", &((ppStd + i)->points.midpoint));
scanf("%d", &((ppStd + i)->points.finpoint));
ppStd[i].points.ava = (ppStd[i].points.midpoint + ppStd[i].points.finpoint) / 2;
}
return ppStd; // 구조체가 반환되지 않고 있음
}
void PrintStud(stud ppStd[], int num)
{
int i;
printf("%8ss%6s%6ss", "이름", "학번", "중간", "기말", "평균");
for (i = 0; i < num; i++)
{
printf("%8sdmm.3lf", ppStd[i].name, ppStd[i].number, ppStd[i].points.midpoint, ppStd[i].points.finpoint, ppStd[i].points.ava);
}
}
void FreeStructure(stud *ppStd)
{
free(ppStd);
}
동적 할당 이후에 값 입력 받고 리턴은 못하네요.. 함수 인자 문제인지...
도와주십쇼
Make structure 매개변수를 그냥 ppstd로해
그리고 scanf &가 아니라 *로 해야된다 주소값넘길때랑 구분잘해야됨
Makestructure 함수는 그냥 다 잘못짠거같은데
Makestructure에서 입력 까지는 아무 이상없이 되는데 메인으로 구조체를 넘기지를 못함 ... 매개변수랑 scanf바꿧는데도 안됨..