我的程序出现编译器错误。我将 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=]
<小时/>该程序的作用:它复制 20 世纪 90 年代手机的一些基本功能。首先,用户选择联系人列表的大小。然后他可以添加联系人、查找联系人或列出所有联系人或退出。
编辑:删除图片并添加更多细节
最佳答案
listNumber 被声明为一个指向 int 的指针:int*
。
&listNumer
的类型为 int**
。
printf 需要一个 int
作为 %d
的参数。
您可能想做的是:
printf("%d", *listLastName);
*
取消引用 listLastName,即允许您访问 int 值。
关于c - 需要类型为 'int' 的参数,但参数 2 的类型为 'int **',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47844711/