I can't understand why i get this error : The error is : "incompatible types when assigning to type 'PERSOANA * {aka struct *}' from type 'PERSOANA {aka struct }' " Can you please explain me where is the mistake ?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char name[20];
char name2[20];
char cnp[15];
} PERSON;
PERSON read_array(int n);
int main()
{
int n;
printf("n = ");
scanf("%d", &n);
PERSON *v;
v = read_array(n); //here i get the error
return 0;
}
PERSON read_array(int n) {
PERSON *v;
v = malloc(n * sizeof(PERSON));
for(int i = 0; i < n; i++) {
printf("name=");
gets(v[i].name);
//more instr
}
return v; // and also here
}
PERSON *read_array(int n)
should be the correct syntax. – Osiris