#include <stdio.h>
#include <stdlib.h>
typedef struct {
int age;
char name[50];
} Person;
void FAMILY_createMembers(int num_members, int *operation_status, Person **family_members) {
family_members*family_members = (Person *) malloc (sizeof(Person) * num_members);
if (family_members == NULL){
*operation_status = 0;
}
else{
*operation_status = 1;
}
}
Family FAMILY_requestFamilyInformationAndCreate(int *operation_status) {
int i;
int num_members;
Person *family_members;
Family family;
printf("Family members? ");
scanf("%d", &num_members);
FAMILY_createMembers(num_members, operation_status, &family_members);
if (*operation_status == 1) {
family.num_members = num_members;
family.family_members = family_members;
for (i = 0; i < family.num_members; i++) {
printf("Name? ");
scanf("%s", family_members[i].name);
printf("Age? ");
scanf("%d", &family_members[i].age);
}
}
return family;
}
Aunque en linea y en la clase me encuentre que asi es como se pasa el malloc cuando un puntero es pasado a una funcion:
*members*family_members = (* Person *) malloc (sizeof(Person) * numnum_members);
El programa que utiliza mi universidad me lleva a un error de "Segmentation fault (core dumped)". Sé que este es el problema porque cuando intento editar la linea solo me aparece problemas en esa linea y y en nada más.
family_members = (Person *) malloc (sizeof(Person) * num_members);
tester.c: In function ‘FAMILY_createMembers’:
tester.c:56:17: error: assignment from incompatible pointer type [-Werror=incompatible-pointer-types]
family_members = (Person *) malloc (sizeof(Person) * num_members);
Que es lo que estoy haciendo mal?