【问题标题】:Expects argument of type 'int', but argument 2 has type 'int **'期望类型为“int”的参数,但参数 2 的类型为“int **”
【发布时间】:2017-12-16 10:33:05
【问题描述】:

我的程序出现编译器错误。我将 Dev-C++ 与 -c99 -wall 和 -pedantic 一起使用。

   #include <stdio.h>

   #include <stdlib.h>

int main(){

    int size,dial,isListEmpty=0,init,i,variableSize,totalSize=0;//Some values I am using 

    printf("Welcome to your New Phone ! Please select the size of contact list\n");//Welcome Message

    scanf("%d", &size);//input of size

    int *listFirstName = (int*)malloc(size*sizeof(int));//Last name (in numbers)

    int *listLastName = (int*)malloc(size*sizeof(int));// First name in numbers

    int *listNumber = (int*)malloc(sizeof(int));// the phone number

    for (init=0 ; init< size ; init++){//initialization of arrays

        listFirstName[init]=-1;

        listLastName[init]=-1;

        listNumber[init]=-1;

    }

这是编译器显示错误的地方。

                        if (dial==3){

        int linearAnswer,possibleLN=0, possibleFN=0,flag=0,j=0;

        printf("Would you like to search by Last Name , First Name? Please press 1 or 2\n");

        scanf("%d",&linearAnswer);

        if(linearAnswer==1){

            scanf("%d",&possibleLN);

            while(j<size){

                if(listLastName[j]==possibleLN){

                    variableSize=j+1;

                    printf("%d",variableSize);

                    printf("\nLast Name:%d\t",&listLastName);

                    printf("First Name:%d\t",&listFirstName);

                    printf("Phone Number:%d",&listNumber);

                    flag=1;

                }

                j++;

            }

编译器错误:

[警告] 格式 '%d' 需要类型为 'int' 的参数,但参数 2 的类型为 'int **' [-Wformat=]


该程序的作用:它复制了 1990 年代手机的一些基本功能。首先,用户选择联系人列表的大小。然后他可以添加联系人、查找联系人或列出所有联系人或退出。

编辑:删除图片并添加更多细节

【问题讨论】:

标签: c arrays malloc


【解决方案1】:

listNumber 被声明为一个指向 int 的指针:int*&amp;listNumer 的类型为 int**。 printf 需要一个int 作为%d 的参数。

您可能想要做的是: printf("%d", *listLastName);

* 取消引用 listLastName,即允许您访问 int 值。

【讨论】:

  • 非常感谢。我现在明白这个问题了。
猜你喜欢
  • 2021-12-12
  • 1970-01-01
  • 2021-06-29
  • 1970-01-01
  • 1970-01-01
  • 2021-07-09
  • 2019-04-03
  • 2014-02-03
  • 1970-01-01
相关资源
最近更新 更多