指向应用程序状态结构的以null结尾的指针数组的指针

时间:2014-05-12 21:27:30

标签: arrays pointers xfs

我需要根据以下内容创建指向以应用程序状态结构指针的以null结尾的指针数组的指针:

typedef struct _wfs_vdm_status
{
WORD wDevice;
WORD wService;
LPWFSVDMAPPSTATUS * lppAppStatus;
LPSTR lpszExtra;
} WFSVDMSTATUS, * LPWFSVDMSTATUS;


typedef struct _wfs_vdm_appstatus
{
LPSTR lpszAppID;
WORD wAppStatus;
} WFSVDMAPPSTATUS, * LPWFSVDMAPPSTATUS;

但是创建lppAppStatus参数非常困难。任何帮助都将受到高度赞赏

1 个答案:

答案 0 :(得分:1)

所以我有点不清楚你想要创建哪些结构。创建_wfs_vdm_appstatus strcuts的空终止数组的一般过程如下:

main (int argc, char **argv)
{
int NUMBER_OF_ELEMENTS=10;
int i = 0;

/* you would allocate your 10 elements and add one to null terminate them */

lppAppStatus = malloc (NUMBER_OF_ELEMENTS+1) * sizeof(LPWFSVDMAPPSTATUS);

/* each of these elements would need to have memory allocated */
for (i=0;i<NUMBER_OF_ELEMENTS;i++)
{
   lppAppStatus[i] = malloc(sizeof (struct _wfs_vdm_appstatus));
}

/* null terminate your array */
lppAppStatus[NUMBER_OF_ELEMENTS] = NULL;

}

我的C有点生疏,所以你可能需要稍微调整一下。