c - 错误: incompatible type for argument in c

标签 c compiler-errors

我必须使用函数minmax(double * x,double * y)输入数组的最小值和最大值。
当我编译它时,会出现一些奇怪的错误:minmax的参数1的类型不兼容; minmax参数2的类型不兼容。但是idk哪里出错了。请解释

问题是输入从文件输入的数组的最大值和最小值。我用一些值填充了文件。
然后从最小到最大对它们进行排序。

#include<stdio.h>
#include<math.h>

void input (int *psize, double arr[]);
void output (int size, double arr[]);
void minmax (double *x, double *y);
int sorting(int size, double arr[]);

int main(){
    double arr[100];
    int size,i;
    input(&size,arr);
    output(size, arr);
    printf("\n");

    sorting(size, arr);
    output(size, arr);

    minmax(arr[0],arr[size-1]);

}

void input (int *psize, double arr[]){
    FILE *array;
    array = fopen("12_3.txt", "r");
    int t_size=0; 
    if (array == NULL){
        printf("CANNOT OPEN FILE");
        exit(1);
    }
    if (array!=NULL)
    {
        while( !feof(array))
            {
            fscanf(array, "%lf", &arr[t_size]); 
            t_size++;
            }
        *psize=t_size-1;
        fclose(array);

    }
}

void output (int size, double arr[]){
    for (int i=0; i<size; i++)
        {
            printf("%f \n",arr[i]);
        }
}

void minmax (double*x, double*y){
    printf("\nmax:  %f\n", *x);
    printf("min:  %f\n", *y);
}

int sorting(int size, double arr[]){
    for (int i = 0; i < size - 1; i++)
        {
        for (int j = 0; j < size - i - 1; j++)
            {
            if (arr[j] > arr[j + 1])
                {
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
                }
            }
        }
}

最佳答案

minmax()的参数-yx-具有指向double(double *)的指针。

调用arr[0]arr[size-1]minmax()的参数类型为double

不匹配。指向doubledouble的指针。

*的定义/声明中,省略xyminmax()运算符:

void minmax (double x, double y) { ...

以及printf()调用时的参数:
printf("\nmax:  %f\n", x);
printf("min:  %f\n", y);

结果:
void minmax (double x, double y);      // Function prototype.

....

void minmax (double x, double y) {     // Function definition.
    printf("\nmax:  %f\n", x);
    printf("min:  %f\n", y);
}

关于c - 错误: incompatible type for argument in c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62132173/

相关文章:

c++ - 大括号或等于初始化程序在 Visual Studio 2015 RC 中导致 C2098 和 C2059

c - 如何将二维数组的一部分复制到一维数组中?

c - 结构声明 : Valid initializer in declaration?

c - GNU Pth(Gnu 可移植线程)的 Windows 端口/实现

visual-c++ - 错误LNK2019 : unresolved external symbol/

jpa - QueryException异常错误

java - 无法切换到 Eclipse Helios 中的编译器合规性级别 1.8

c - OpenMP 嵌套循环并行性

c - 如何检查字符串中某个位置的数字并在c中提取其值?

python - 属性错误 : 'str' object has no attribute 'read' Python urllib2