Reputation: 53
#include<stdio.h>
#include<string.h>
#include<malloc.h>
typedef struct male_node
{
int mv1,mv2,mv3;
}male;
typedef struct movie_name
{
char mvnm[20];
struct male *ml;
}movie;
main()
{
movie mov1;
mov1.ml=(male*)malloc(sizeof(male));
mov1.(*ml).mv1=1;//ERROR
mov1.ml->mv1=1; //ERROR
}
How to access the mv1 variable through mov1 and ml I tried to access mv1 through ml which is a pointer to a structure which is again a structure variable but it shows error.
Upvotes: 3
Views: 103
Reputation: 124997
This looks wrong:
struct male *ml;
You've used typedef
to define male
as struct male_node
, so it doesn't make sense to say struct male
. Instead, try this:
typedef struct movie_name
{
char mvnm[20];
male *ml;
} movie;
That should fix your problem, and you should be able to do this:
mov1.ml->mv1=1;
Upvotes: 4