以下のように、main関数でポインタを宣言して、他の関数を経由して、値を取得したい場合には
どのようにすればいいのでしょうか?
このプログラムを実行した場合、 point関数で値を表示しようとすれば、menseki関数で定義された値を表示
できますが、その呼び出し元のmain関数では、point関数が終了した時点で領域が消えるので値の表示ができません。
main関数で SQUARE_tをポインタで宣言しなければできるのはわかるのですが、ポインタで宣言した場合の方法が知りたいです。
#include <stdio.h>
typedef struct
{
int x;
int y;
int h;
int w;
} SQUARE_t;
void point (SQUARE_t *);
SQUARE_t *menseki ();
int main(void)
{
SQUARE_t *square;
point(square);
printf("x[%d]\n",square->x);
printf("y[%d]\n",square->y);
printf("h[%d]\n",square->h);
printf("w[%d]\n",square->w);
return 0;
}
void point(SQUARE_t *square)
{
square = menseki();
}
SQUARE_t *menseki ()
{
static SQUARE_t square;
square.x = 0;
square.x = 1;
square.x = 2;
square.x = 3;
return □
}