I would like to access the name field from the array items and print the name but I am having trouble.
I created a pointer 'L' in callInitialize and set it to the upper struct type List which I named 'studentList'.
int callInitialize () {
/*Initialize a List*/
List studentList;
List *L;
L = &studentList;
Initialize(L);
#ifdef DEBUG
printf("L->count after function call Initialize = %d\n", L->count);
printf("L->items[0].name after function call Initialize = %s\n", studentList.items[0].name);
#endif
return 0;
}
I then called Initialize and tried to set the value to test but this is incorrect.
void Initialize (List *L) {
char test = "I like you";
L->count = 0;
L->items[0].name = test;
}
I am unsure of why L->items[0].name = test; is not appropriate. I am getting an incompatible types error but name is char and test is char?
Also, once I do change that value how would I print that? My thinking was that %s would be correct since the type of the field name is char. Print is above in callIntialize as a debug statement.
My struct declarations:
#define MAXNAMESIZE 20
typedef struct {
char name[MAXNAMESIZE];
int grade;
} Student;
typedef Student Item;
#define MAXLISTSIZE 4
typedef struct {
Item items[MAXLISTSIZE];
int count;
} List;
Thank you for any help.