嗨,朋友,我是新手,正在尝试学习结构...在这里我已经在结构计算中声明了结构日期...但不知道如何从日期访问元素。我通过使用 malloc 为父结构 calc 保留了内存。这对于日期结构也足够了吗?.请指导我...谢谢!
#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 to understand that where i need to resever seprate memory for date?
my_calc[0] = (struct calc *)malloc(sizeof(struct calc));
//trying to asign the 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 to print the 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;
}