/* * Sample answer * Author: Programming C teaching group * Date: 2026/10/26 */ #include #define N 15 typedef struct{ int id; /* ID */ char name[12]; /* 名前 */ int year; /* 学年 */ char subject[12]; /* 科目名 */ char grade; /* 成績 */ }CourseRecord; void PrintRecord(CourseRecord); void PrintRecordPtr(CourseRecord *); int InputRecord(CourseRecord *); int main() { CourseRecord studentrecords[N]; int i, count; /* 入力 */ for(i = 0; i < N; i++){ if(InputRecord(&studentrecords[i]) == EOF) break; } count = i; printf("構造体の値渡し (PrintRecord)\n"); for(i = 0; i < count; i++) PrintRecord(studentrecords[i]); printf("構造体のアドレス値渡し (PrintRecordPtr)\n"); for(i = 0; i < count; i++) PrintRecordPtr(&studentrecords[i]); return 0; } void PrintRecord(CourseRecord s){ printf("%d %12s %d %12s %c\n", s.id, s.name, s.year, s.subject, s.grade); } void PrintRecordPtr(CourseRecord *s){ printf("%d %12s %d %12s %c\n", s->id, s->name, s->year, s->subject, s->grade); } /* 入力用 */ int InputRecord(CourseRecord *s){ return scanf("%d %s %d %s %c", &s->id, s->name, &s->year, s->subject, &s->grade); }