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

时间:2014-07-31 16:53:24

标签: c prototype conflict incompatibility

#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);
        }
}

错误::

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

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

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

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

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

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

1 个答案:

答案 0 :(得分:3)

你有以下原型:

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

然后你将它们声明为:

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

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

存在问题。你的原型采用单个双精度作为参数,而不是双精度数组。然后,在原型中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)