c - Using structure in structure..unable ot access inner structure elements? -


hi friend new , trying learn structure...here have declared structure date in structure calc...but not getting idea how access elements date. have reserved memory using malloc parent structure calc..will sufficient date structure well? .please guide me...thanks!

#include <stdio.h> #include <stdlib.h>  struct date{    int day;    int month;    int year; };  struct calc{    int row;    int col;    char menu_name[20];    char sub_menu_name[20];    struct date dob; };  int main() {     int count = 0, i;     struct calc *my_calc[2];     //here unable understand need resever seprate memory date?    my_calc[0] = (struct calc *)malloc(sizeof(struct calc));      //trying asign date value     for(count; count<2; count++)    {           printf("please enter day: ");            scanf("%d",&my_calc[count]->date.day);         printf("please enter month: ");            scanf("%d",&my_calc[count]->date.month);         printf("please enter year: ");            scanf("%d",&my_calc[count]->date.year);    }     //trying print date value     printf("day: %d\t  month: %d\t   year: %d\n ",my_calc[0]->date.day,my_calc[0]->date.month,my_calc[0]->date.year);     system("pause");     return 0; } 

you declare dob not date. &my_calc[count]->dob.day


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -