0

I need to create a Pointer to a null-terminated array of pointers to Application Status structures based on:

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;

but have had a really hard time creating the lppAppStatus parameter. Any help would be highly appreciated

A. Lop
  • 1

1 Answers1

1

So I am bit unclear which of your structures you are trying to create. The general process to create a null terminated array of _wfs_vdm_appstatus strcuts would be as follows

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;

}

My C is a bit rusty so you might need to fiddle with this a bit.

ojblass
  • 21,146
  • 22
  • 83
  • 132