Array of structs in C

后端 未结 5 1629
执笔经年
执笔经年 2021-01-05 23:33

I\'m trying to create an array of structs and also a pointer to that array. I don\'t know how large the array is going to be, so it should be dynamic. My struct would look s

5条回答
  •  暖寄归人
    2021-01-06 00:15

    The second option of a pointer is good.

    If you want to allocate things dynamically, then try:

    stats_t* theStatsPointer = (stats_t*) malloc( MAX * sizeof(stats_t) );
    

    as Roland suggests.

    Just don't forget to

    free(theStatsPointer);
    

    when you're done.

提交回复
热议问题