嗨,朋友,我是新的,並試圖學習結構...在這裏我已經聲明結構日期結構calc ...但沒有得到想法如何從日期訪問元素。我已經使用malloc保留了內存,用於父結構calc..will,這對於日期結構來說足夠了嗎? 。請引導我...謝謝!在結構中使用結構..不能訪問內部結構元素?
#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;
}
非常感謝,我真的很愚蠢成爲...我會確保這將不會重複...對不起......坦克。 – studyembedded 2013-03-13 11:08:51