gpt4 book ai didi

c - 结构体指针 结构体指针

转载 作者:行者123 更新时间:2023-11-30 20:14:11 25 4
gpt4 key购买 nike

我无法让它工作!抛出段错误。

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
size_t NbOfElmts;

float * Weights;
int * Areas;

} ListOfCoeff;

typedef struct
{
size_t NbOfElmts;

ListOfCoeff * Elmts;


} SetOfListsOfCoeff;



int main( int argc, const char* argv[] ){

SetOfListsOfCoeff * theList;

int N = 10;
float *A = malloc( N * sizeof(*A) );

for ( int i = 0; i < N; i++)
A[ i ] = i;


for ( int i = 0; i < N; i++ )
( (theList[ i ].Elmts)->Weights)[ i ] = A[ i ];


for ( int i = 0; i < N; i++)
printf("\n List = %f", ( (theList[ i ].Elmts)->Weights)[ i ] );

return 0;


}

该行的问题:

( (theList[ i ].Elmts)->Weights)[ i ] = A[ i ];

最佳答案

您尚未为 theList 分配任何内存。

关于c - 结构体指针 结构体指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27298352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com