私には2つの構造体があります:
struct first
{
int* array;
}
struct second
{
struct first* firsts;
} *SECOND;
どこかで、そのインデックスstruct first
からいずれかのアドレスを取得できるとしましょうSECOND->firsts
。array
この構造体をどのように取得できますか?私はもう試した
SECOND->firsts[index]->array
しかし、expression must have pointer-to-struct-or-union type
エラーがあります。
mallocチェックも無料もありません-アイデアを示すためだけに
struct first {
int* array; };
struct second {
struct first* firsts; } *SECOND;
#define NUMFIRSTS 50
#define ARRSIZE 50
int main() {
SECOND = malloc(sizeof(*SECOND));
SECOND -> firsts = malloc(NUMFIRSTS * sizeof(*SECOND -> firsts));
for(int f = 0; f < NUMFIRSTS; f++)
{
SECOND -> firsts[f].array = malloc(ARRSIZE * sizeof(*SECOND -> firsts[f].array));
}
//access
SECOND -> firsts[5].array[10] = 23;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加