I'm a beginner in C.
I want to assign each person's info to an array of pointer that is *arr[2]
but I get an error message that is
'malloc' is not declared in this scope.
How can I fix it?
#include <stdio.h>
int main()
{
struct person {
char *name;
int number;
char gender;
};
struct person *arr[2];
arr[0] = (struct person *) malloc(sizeof(struct person));
arr[0]->name = "john";
arr[0]->number = 123;
arr[0]->gender ='m';
arr[1] = (struct person *) malloc(sizeof(struct person));
arr[1]->name = "jessica";
arr[1]->number = 456;
arr[1]->gender ='w';
printf("%s", arr[1]->name);
return 0;
}