A step by step compiler says "Invalid write of size 4", while in general it's a segmentation fault. I don't understand how to solve this. I have been fidgeting with this for the past few hours. What am I missing?
typedef struct Person{
int age;
char name[6]
} Person;
fun(Person **parray){
*parray = realloc(*parray, 6 * (sizeof(Person)));
for(int i = 0; i < 6; ++i){
strcpy (parray[i]->name, "John");
parray[i]->age = 15;
}
}
int main() {
Person *parray;
parray = calloc(0, sizeof(Person));
fun(&parray);
return 0;
}
question from:https://stackoverflow.com/questions/65894702/i-simplified-a-part-of-my-project-to-solve-this-specific-problem-i-have-invalid