# include <Windows.h>
# include <stdio.h>
# include <string.h>
// 구조체와 배열
struct Student {
int code;
char* name;
char subs[3][100] = { {"java"}, {"jsp"}, {"c"} };
int* score;
void print() {
printf("학번 : %d\n", code);
printf("이름 : %s\n", name);
for (int i = 0; i < sizeof(subs)/100; i++) {
printf("%d) %s : %d점\n", i + 1, subs[i], score[i]);
}
}
};
void main() {
Student st = { 0 };
char name[100] = { 0 };
printf("이름입력 : ");
scanf_s("%s", name, 100);
st.name = new char[strlen(name) + 1];
strcpy_s(st.name, strlen(name) + 1, name);
st.code = 1004;
printf("sizeof(subs) : %d\n", sizeof(st.subs));
printf("<성적입력>\n");
st.score = new int[sizeof(st.subs)];
for (int i = 0; i < sizeof(st.subs)/100; i++) {
printf("%s : ", st.subs[i]);
scanf_s("%d", &st.score[i]);
}
printf("\n");
st.print();
system("pause");
}
댓글