Tengo un problema al inicializar una matriz de estructuras. No estoy seguro si lo estoy haciendo bien porque obtengo "inicialización del tipo de puntero incompatible" & "asignación del tipo de puntero incompatible". He añadido en el código donde consigo estas advertencias, y cuando intento imprimir los datos de la estructura apenas consigo la basura como @@ ###C - initialize array of structs
typedef struct
{
char* firstName;
char* lastName;
int day;
int month;
int year;
}student;
// inicializar gama
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;
// añadir 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++;
Parece que su código está a medio camino entre crear dinámicamente una matriz de estructuras de alumnos y crear dinámicamente una matriz de punteros a las estructuras de los alumnos, y luego crear dinámicamente cada estructura de alumno a la que se apunta. No es obvio cuál estás tratando de hacer, lo que hace que contestar esto sea difícil. –