#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
// 科目構造体:ten.h
struct t_rec {
int kamoku[3];
};
// 学生情報構造体:gaku3.h
struct g_rec {
char gakuban[9];
char cls[5];
char *pnamae;
int sei;
struct t_rec *pten;
struct g_rec *pgnext;
};
struct g_rec *new_record(void)
{
struct g_rec *pg;
int i;
pg
= (struct g_rec
*)malloc(sizeof (struct g_rec
)); pg
->pnamae
= (char *)malloc(20); pg
->pten
= (struct t_rec
*)malloc(sizeof (struct t_rec
));
scanf("%8s", pg
->gakuban
); scanf("%19s", pg
->pnamae
); for (i = 0; i < 3; i++) {
scanf("%d", &pg
->pten
->kamoku
[i
]); }
return pg;
}
int main()
{
struct g_rec *pghead = NULL;
struct g_rec *pg;
struct g_rec *pgnext;
int i, num;
for (i = 0; i < num; i++) {
pgnext = new_record();
pgnext->pgnext = NULL;
if (pghead == NULL) {
pghead = pgnext;
continue;
}
for (pg = pghead; ; pg = pg->pgnext) {
if (pg->pgnext == NULL) {
pg->pgnext = pgnext;
break;
}
}
}
// リストの表示
for (pg = pghead; pg; ) {
printf("学籍番号:%s\n", pg
->gakuban
); printf("氏名:%s\n", pg
->pnamae
); printf("性別:%s\n", (pg
->sei
== 1) ? "男" : "女"); for (i = 0; i < 3; i++) {
printf("点数%d:%d\n", i
+1, pg
->pten
->kamoku
[i
]); }
pg = pg->pgnext;
}
// リストの削除
for (pg = pghead; pg; pg = pgnext) {
pgnext = pg->pgnext;
}
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUwojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0ZGxpYi5oPgoKLy8g56eR55uu5qeL6YCg5L2TOnRlbi5oCnN0cnVjdCB0X3JlYyB7CglpbnQga2Ftb2t1WzNdOwp9OwoKLy8g5a2m55Sf5oOF5aCx5qeL6YCg5L2TOmdha3UzLmgKc3RydWN0IGdfcmVjIHsKCWNoYXIgZ2FrdWJhbls5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