指向结构指针的指针

时间:2014-12-04 15:57:12

标签: c

我无法让它发挥作用! 抛出错误。

#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 ];

1 个答案:

答案 0 :(得分:2)

您尚未为列表分配任何内存。