Hi,
I'm working on my second C program, but I can't figure out
how to access the Array of strings in the C Structure below.
Could someone please show me how ? I'm really lost on this.
I need to use pointers to access the structure.
* My code
Code:
#include "stdafx.h"
#include <string.h>
typedef struct st {
char *name;
int id;
char *items[3]; // MAKE IT AN ARRAY
};
int _tmain(int argc, _TCHAR* argv[])
{
struct st my_emp;
struct st *pmy_emp;
//ADDED
pmy_emp = (struct st *) malloc(sizeof(struct st));
my_emp.name="Someones Name";
my_emp.id = 6;
pmy_emp = &my_emp;
// CHANGED
strcat(my_emp.items[0],"Cats");
strcat(my_emp.items[1],"Dogs");
//WAS
//pmy_emp->items = "Cats","Dogs";
printf ("STRUCT TEST... = %s\n", pmy_emp->name);
for(int x=0;x < 2; x++){
printf ("ITEMS = %s\n", pmy_emp->items[x]);
}
return 0;
}
END ************
Thanks,
-Areal