user971089
user971089

Reputation: 53

accessing structure variable through pointer

#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

Answers (1)

Caleb
Caleb

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

Related Questions