I am having a problem initializing an array of structs. I'm not sure if I am doing it right because I get "initialization from incompatible pointer type" & "assignment from incompatible pointer type". I added in the code where I get these warnings, and when I try to print the data from the struct I just get garbage such as @@###
typedef struct
{
char* firstName;
char* lastName;
int day;
int month;
int year;
}student;
//initialize array
student** students = malloc(sizeof(student));
int x;
for(x = 0; x < numStudents; x++)
{
//here I get: "assignment from incompatible pointer type"
students[x] = (struct student*)malloc(sizeof(student));
}
int arrayIndex = 0;
//add struct
//create student struct
//here I get: "initialization from incompatible pointer type"
student* newStudent = {"john", "smith", 1, 12, 1983};
//add it to the array
students[arrayIndex] = newStudent;
arrayIndex++;
See Question&Answers more detail:os