程序在编译时出现了cannot convert parameter 1 from 'int [30]' to 'int'的问题,怎么解决?
#include<stdio.h>#defineN30intReadscore(intscore,longnum[]);voidPrintscore(intscore,l...
#include<stdio.h>
#define N 30
int Readscore(int score,long num[]);
void Printscore(int score,long num[],int n);
void Select(int a[],long b[],int n,int(*compare)(int a,int b));
int Asc(int a,int b);
int Des(int a,int b);
void Swap1(int *x,int *y);
void Swap2(long *x,long *y);
int main()
{
int score[N],n,order;
long num[N];
n = Readscore(score,num);
printf("Input 1 to sort in ascending order:\n");
printf("Input 2 to sort in descending order:\n");
scanf("%d",&order);
if(order == 1)
{
Select(score,num,n,Asc);
printf("ascending order:\n");
}
else
{
Select(score,num,n,Des);
printf("descending order:\n");
}
Printscore(score,num,n);
return 0;
}
int Readscore(int score[],long num[])
{
int i = -1;
do{
i++;
printf("Input score:");
scanf("%ld%d",num[i],score[i]);
}while(num[i]>=0&&score[i]>=0);
return i;
}
void Printscore(int score[],long num[],int n)
{
int i;
for(i = 0;i<n;i++)
{
printf("%ld %4d",num[i],score[i]);
}
printf("\n");
}
void Select(int a[],long b[],int n,int (*compare)(int a,int b))
{
int i,j,k;
for(i = 0;i<n-1;i++)
{
k = i;
for(j = i+1;j<n;j++)
{
if((*compare)(a[j],a[k]))
{
k = j;
}
}
if(k != i)
{
Swap1(&a[k],&a[i]);
Swap2(&b[k],&b[i]);
}
}
}
int Asc(int a,int b)
{
return a<b;
}
int Des(int a,int b)
{
return a>b;
}
void Swap1(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void Swap2(long *x,long *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
} 展开
#define N 30
int Readscore(int score,long num[]);
void Printscore(int score,long num[],int n);
void Select(int a[],long b[],int n,int(*compare)(int a,int b));
int Asc(int a,int b);
int Des(int a,int b);
void Swap1(int *x,int *y);
void Swap2(long *x,long *y);
int main()
{
int score[N],n,order;
long num[N];
n = Readscore(score,num);
printf("Input 1 to sort in ascending order:\n");
printf("Input 2 to sort in descending order:\n");
scanf("%d",&order);
if(order == 1)
{
Select(score,num,n,Asc);
printf("ascending order:\n");
}
else
{
Select(score,num,n,Des);
printf("descending order:\n");
}
Printscore(score,num,n);
return 0;
}
int Readscore(int score[],long num[])
{
int i = -1;
do{
i++;
printf("Input score:");
scanf("%ld%d",num[i],score[i]);
}while(num[i]>=0&&score[i]>=0);
return i;
}
void Printscore(int score[],long num[],int n)
{
int i;
for(i = 0;i<n;i++)
{
printf("%ld %4d",num[i],score[i]);
}
printf("\n");
}
void Select(int a[],long b[],int n,int (*compare)(int a,int b))
{
int i,j,k;
for(i = 0;i<n-1;i++)
{
k = i;
for(j = i+1;j<n;j++)
{
if((*compare)(a[j],a[k]))
{
k = j;
}
}
if(k != i)
{
Swap1(&a[k],&a[i]);
Swap2(&b[k],&b[i]);
}
}
}
int Asc(int a,int b)
{
return a<b;
}
int Des(int a,int b)
{
return a>b;
}
void Swap1(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void Swap2(long *x,long *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
} 展开
1个回答
展开全部
int Readscore(int score,long num[]);
void Printscore(int score,long num[],int n);
这两个函数声明时第一个参数都是int,但在调用时传入的都是score,其是int[30]的数组,所以编译报错, 修改声明为int Readscore(int score[],long num[]); 和void Printscore(int score[],long num[],int n); 应该就不会报这个错误了。
不改的话声明和最后的实现都不一致了,过不了编译。
void Printscore(int score,long num[],int n);
这两个函数声明时第一个参数都是int,但在调用时传入的都是score,其是int[30]的数组,所以编译报错, 修改声明为int Readscore(int score[],long num[]); 和void Printscore(int score[],long num[],int n); 应该就不会报这个错误了。
不改的话声明和最后的实现都不一致了,过不了编译。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询