我有这个结构并使用指针,我试图打印不同结构变量的值,但是对于 int 变量,它打印位置地址而不是值,对于 char 变量,结果是正确的。
#include <stdio.h>
#include <stdlib.h>
struct calc{
int row;
int col;
int menu_name[20];
int sub_menu_name[20];
};
int main()
{
int count = 0, i = 0;
struct calc *P_calc[2];
//p_calc = (struct calc *)malloc(sizeof(struct calc)*2);
for(count; count<1; count++)
{
P_calc[count] = (struct calc *)malloc(sizeof(struct calc));
printf("Please enter the row cordinates: \n");
scanf("%d",P_calc[i]->row);
printf("Please enter the col cordinates: \n");
scanf("%d",P_calc[i]->col);
printf("Please enter the menu_name: \n");
scanf("%s",P_calc[i]->menu_name);
printf("Please enter the sub_menu_name: \n");
scanf("%s",P_calc[i]->sub_menu_name);
}
for(i; i<1; i++)
{
printf("row : %d\n",P_calc[i]->row);
printf("col :%d\n",P_calc[i]->col);
printf("menu_name: %s\n",P_calc[i]->menu_name);
printf("sub_menu_name :%s\n",P_calc[i]->sub_menu_name);
}
system("PAUSE");
return 0;
}
请帮我。
提前致谢。