//The struct
typedef struct {
int nr;
char *nume, **mesaj;
} utilizator;
void citire_mesaje(utilizator *user, int n)
{
user->nr = malloc (n * sizeof(int));
scanf("%d", &user[0].nr);
printf("user[0].nr = %d\n", user[0].nr);
}
int main()
{
int n;
utilizator *user = malloc (sizeof(utilizator));
citire_mesaje(user, n);
return 0;
}
What am I doing wrong? I used user[0].nr just to test it more easily. I can get it work if I only use one element of type struct (utilizator user;), but I can't figure it out if I use a pointer. I get:
warning: assignment makes integer from pointer without a cast [enabled by default]
user->nr = malloc (n * sizeof(int));
^
Any suggestions?
user->nr = malloc (n * sizeof(int))because it is already secured area. On the contrary nr update byscanf(is making an area that can not be released) memory leak.