传递"函数名称"的参数 3 使指针从整数不带强制转换



所以我有一项大学作业,用户从他提供的一组类别中键入一些产品的价格,我必须找到他能花的最大金额。我还需要使用一个函数进行计算。我在下面输入了代码,它显示了两个警告:

line 21 [Warning] passing argument 3 of 'shop' makes pointer from integer without a cast,
line 21 [Warning] passing argument 4 of 'shop' makes pointer from integer without a cast

和2个音符:

line 4 [Note] expected 'int *' but argument is of type 'int', 
line 4 [Note] expected 'int (*)[10]' but argument is of type 'int'

代码是这样的,值得一提的是,我们被要求使用一个头文件来将主程序与函数结合起来,而不是将所有内容写在一页中:

#include <stdio.h>
#include "shoprec.h"
int shop(int m, int n, int K[n], int C[n][10]);
int main(){
int m, n, i, j,  R;
printf("please type the maximum amount of money you want to spend n");
scanf("%d", &m);
printf("please type how many kinds of products you want to buy (like pc, printers. scanners etc.) n");
scanf("%d", &n);
int K[n],C[n][10];
for (i=1; i<=n; i++){
printf("please type the amount of available products for category number %d n", i);
scanf("%d", &K[i]);
for (j=1; j<=K[i]; j++){
printf("please type the cost of product number %d from category number %d n", j, i);
scanf("%d", &C[i][j]);
}
}
R= shop(m, n, K[n], C[n][10]);
printf ("Maximum amount spent is : %d n",R)
}

头文件是这样的:

int shop(int m, int n, int K[n], int C[n][10]);

功能代码为:

int shop(int m, int n, int K[n], int C[n][10]){
int P,i,j,R;
P=m;
R=0;
for (i=1;i<=n;i++){
for (j=1;j<=K[i];j++){
P=P-C[i][j];
}
if (P>R) R=P;
}
return R;
}

R= shop(m, n, K[n], C[n][10]);更改为R= shop(m, n, K, C);

当您放置K[n]时,您传递的是int,而不是函数签名指定的int array

最新更新