0

私はこの構造を持ち、ポインターを使用して、さまざまな構造変数の値を出力しようとしていますが、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;    
}

私を助けてください。

前もって感謝します。

4

2 に答える 2

3

ここにあなたの問題があります:

  1. 構造は

    struct calc{
    
    int row;
    int col;
    char menu_name[20];
    char sub_menu_name[20]; 
    
    };
    
  2. scanf("%d",P_calc[i]->row);する必要がありますscanf("%d",&P_calc[i]->row);

  3. scanf("%d",P_calc[i]->col);する必要がありますscanf("%d",&P_calc[i]->col);

からの戻り値を確認することもお勧めしますscanf

于 2013-03-13T05:50:45.280 に答える
0

scanf ステートメントは、

scanf("%d",&P_calc[i]->row);

アドレスを scanf に渡す必要があります。同様に、col 変数を読み取ります。

于 2013-03-13T05:49:37.633 に答える