3
#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.

4
  • Can you post what error is returning? Commented Apr 29, 2014 at 18:41
  • 2
    I know that you don't have to put an int in front of main but it hurts my heart when I see it is missing. Commented Apr 29, 2014 at 18:42
  • Does modern C really still allow omitting return types? Commented Apr 29, 2014 at 18:49
  • 1
    @RobK: No, it's required now. Commented Apr 29, 2014 at 18:50

1 Answer 1

4

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You. Actually I did not noticed that. It now works fine.
and mov1.(*ml).mv1=1; to (*mov1.ml).mv1=1;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.