構造体を使った配列へのアクセス
code:c
//構造体
typedef struct {
int test1;
int test2;
int test3;
} Gtest;
//staticを使用し、起動時からファイル内グローバル変数。メイン関数に入る前に、呼ばれる。
{ 0, 0, 0}, // 0
{ 1, 2, 3}, // 1
{ 4, 5, 6}, // 2
};
int main(void){
// Your code here!
for(int i=0;i<SETNUM;i++){
printf("ptest=%d\n",ptest->test1);
printf("ptest=%d\n",ptest->test2);
printf("ptest=%d\n",ptest->test3);
}
}
code:c
//構造体
typedef struct {
int test1;
int test2;
int test3;
} Gtest;
//staticを使用し、起動時からファイル内グローバル変数。メイン関数に入る前に、呼ばれる。
// Gtest構造体の配列を1つ用意し、test1, test2, test3を0で初期化
{0, 0, 0} // 1つのGtest構造体を全て0で初期化
};
static Gtest tes3={0,1,2}; void TesSet(Gtest *ptest);
int main(void){
printf("ptest=%d\n",ptest->test1);
printf("ptest=%d\n",ptest->test2);
printf("ptest=%d\n",ptest->test3);
TesSet(ptest);
printf("ptest=%d\n",ptest->test1);
printf("ptest=%d\n",ptest->test2);
printf("ptest=%d\n",ptest->test3);
}
void TesSet(Gtest *ptest){
ptest->test1 = 2;
}