不兼容的参数类型和冲突类型。

时间:2022-10-24 19:37:54
#include <stdio.h>

void copy_arr(double, double, int);
void copy_ptr(double, double *, int);

int main()
{

    double source[5]={1.1,2.2,3.3,4.4,5.5}; 
    double target1[5]={0.0};
    double target2[5]={0.0};
    copy_arr(source, target1, 5);
    copy_ptr(source, target2, 5);
    return 0;
}

void copy_arr(double source[5],double target1[5],int arraysize)
{
    int count=0;
    puts("....copying using array notation.....");
    for(count=0;count<arraysize;count++)
        {
            target1[count]=source[count];
            printf("target 1 is : %d\t", target1[count]);
        }
}

double copy_ptr(double source[5],double *target2,int arraysize)
{
    int count=0;
    puts("....copying using pointer notation.....");
    for(count=0;count<arraysize;count++)
        {
            *(target2+count)=source[count];
            printf("target 2 is : %f\t", *target2);
        }
}

Errors::

错误::

error: incompatible type for argument 1 of ‘copy_arr’ copy_arr(source, target1, 5);

错误:' copy_arr ' copy_arr(源,target1, 5)的参数1的不兼容类型;

error: incompatible type for argument 2 of ‘copy_arr’ copy_arr(source, target1, 5);

错误:' copy_arr ' copy_arr(源,target1, 5)的参数2的不兼容类型;

error: incompatible type for argument 1 of ‘copy_ptr’ copy_ptr(source, target2, 5);

错误:' copy_ptr ' copy_ptr(源,target2, 5)的参数1的不兼容类型;

error: conflicting types for ‘copy_arr’ void copy_arr(double source[5],double target1[5],int arraysize)

错误:' copy_arr ' void copy_arr的冲突类型(double source[5],double target1[5],int arraysize)

error: conflicting types for ‘copy_ptr’ void copy_ptr(double source[5],double *target2,int arraysize)

错误:“copy_ptr”void copy_ptr(双源[5],double *target2,int arraysize)的冲突类型

I checked in internet but everything was mostly about prototypes. Mine are here but still I am getting this error! What is the reason?

我在网上查过,但一切都是关于原型的。我的在这里,但我仍然得到这个错误!的原因是什么?

1 个解决方案

#1


3  

you have following prototypes:

你有下面的原型:

void copy_arr(double, double, int);
void copy_ptr(double, double *, int);

then you declare those as:

然后你声明如下:

void copy_arr(double source[5],double target1[5],int arraysize)

and

double copy_ptr(double source[5],double *target2,int arraysize)

there's a problem. your prototypes take single doubles as arguments, not arrays of doubles. then, in prototype copy_ptr returns nothing, but in declaration returns double. change those to:

有一个问题。您的原型将单个双精度作为参数,而不是双精度数组。然后,在prototype copy_ptr中没有返回任何东西,但是在声明中返回double。改变这些:

void copy_arr(double[], double[], int);
void copy_ptr(double[], double *, int);
...
void copy_arr(double source[],double target1[],int arraysize)
void copy_ptr(double source[],double *target2,int arraysize)

#1


3  

you have following prototypes:

你有下面的原型:

void copy_arr(double, double, int);
void copy_ptr(double, double *, int);

then you declare those as:

然后你声明如下:

void copy_arr(double source[5],double target1[5],int arraysize)

and

double copy_ptr(double source[5],double *target2,int arraysize)

there's a problem. your prototypes take single doubles as arguments, not arrays of doubles. then, in prototype copy_ptr returns nothing, but in declaration returns double. change those to:

有一个问题。您的原型将单个双精度作为参数,而不是双精度数组。然后,在prototype copy_ptr中没有返回任何东西,但是在声明中返回double。改变这些:

void copy_arr(double[], double[], int);
void copy_ptr(double[], double *, int);
...
void copy_arr(double source[],double target1[],int arraysize)
void copy_ptr(double source[],double *target2,int arraysize)