0

我需要创建一个指向应用程序状态结构的指针的空终止数组的指针:

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 参数。任何帮助将不胜感激

4

1 回答 1

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 有点生锈,所以你可能需要稍微摆弄一下。

于 2014-05-12T21:42:59.720 回答