我无法解决这个警告
这是我的原型(prototype)
int doubeInput (int* inputVal);
int squareInput (int* inputVal);
int cubeInput (int* inputVal);
出错的行是
int (*funPtrArr[])(int)={doubleInput, squareInput, cubeInput};
这条线在主线
while (choice >0 && choice <=3)
{
(*funPtrArr[choice])(inputVal);
}
这是我的功能
//function to perform the menu option 1,user input passed in
int doubleInput (int* inputVal)
{
//calculate double
int answer = (*inputVal) *= (2);
printf("%d x 2", inputVal);
return (answer);
}
//function to perform the menu option 2,user input passed in
int squareInput (int* inputVal)
{
//calculate square
int answer = (*inputVal) *= (*inputVal);
printf("%d x %d", inputVal, inputVal);
return (answer);
}
//function to perform the menu option 3,user input passed in
int cubeInput (int* inputVal)
{
//calculate cube
int answer = (*inputVal) *= (*inputVal) *= (*inputVal);
printf("%d ^ 3", inputVal);
return (answer);
}
我不断收到此错误,我是 C 的新手。我的功能尚未完成,因为我无法测试它们。 请帮忙
最佳答案
int (*funPtrArr[])(int)
声明了一个指针数组,指向带有 int
参数的函数,但您的函数有一个 int *
参数。
所以该行应该是
int (*funPtrArr[])(int *)={doubleInput, squareInput, cubeInput};
关于c - 来自不兼容指针类型的警告初始化 - C 函数指针数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58417160/