#include <stdio.h>
#include <string.h>
#define NAMELENGTH 20
#define MAXPEOPLE 10
struct people{
char name[NAMELENGTH];
int ratings[MAXPEOPLE];
};
int main(void)
{
struct people *men[MAXPEOPLE];
strcpy(men[2]->name,"pie");
return 0;
}
It crashes upon trying to assign any value to men[2]->name
men[]->name is a char array and the first two slots men[0]->name and men[1]->name work fine.
You have only created an array of pointers, not an array of
struct people:This only creates an array of pointers, but the pointers don’t yet point to anything because you haven’t allocated any space for them. This means that you are copying into a
namethat doesn’t actually exist. To create an array ofstruct peopleyou want: