[英]How do I null an array of pointers that is pointing to a Structure in C (not C++)
我目前正在嘗試使指向結構的指針數組為空。 任何幫助或文檔將是很好的。 我是初學者,所以請盡可能清楚。
這是我的代碼示例。 抱歉,如果我沒有正確列出此信息,這是我的第一個發布信息。請在此處輸入代碼
#include "stdlib.h"
enum boxtype
{
Card,
Mask,
};
typedef struct
{
enum boxtype type;
int L;
int H;
int x;
int y;
int Area;
Float ManBox;
Float WomanBox;
}Boxes;
typedef struct
{
Boxes Info;
float Hight;
}Male;
typedef struct
{
Boxes Info;
int Size;
}Female;
void main()
{
Man Male[100];
Woman Female[100];
Boxes *Spaces[600]; //This is the array of pointers that needs to be nulled.
}
您可以使用初始化列表初始化數組,如下所示:
Boxes *Spaces[600] = { NULL };
數組中的所有元素都將設置為NULL。
如果使用calloc()
初始化,則內存將在返回之前歸零。
for(int i=0;i<600;i++) { *Space[i]=NULL; }
for(int i=0;i<600;i++) { *Space[i]=NULL; }
先前給出的答案也是正確的。 如果您不理解前面的代碼,則可以嘗試使用此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.