/* 構造体の配列 */ #include #include typedef struct data { char name[20]; int age; float weight; float height; } DATA, *Data; /* DATA は struct data 型 Data は struct data 型へのポインタ */ void prdata( Data dp ) { printf("名前 = %s\n", dp->name ); printf("年齢 = %d\n", dp->age ); printf("体重 = %3.1f\n", dp->weight ); printf("身長 = %3.1f\n", dp->height ); printf("---------------\n"); } main() { /* 構造体の配列の初期化 */ DATA ourdata[4] = { { "山田太郎", 18, 80.0, 170.0 }, { "鈴木健史", 17, 75.0, 175.0 }, { "佐藤博司", 19, 90.0, 180.0 }, { "", 0, 0, 0 } }; int datanum = 3; int i; for( i = 0; i < datanum; i++ ) prdata( &ourdata[i] ); } /* end of structa.c */