大佬求助
写的是数组内容,将已知数组拷贝到其它三个数组内,第一个数组是使用带数组表示法的函数;第二个数组是使用带指针表示法和指针递增的函数;第三个是以目标数组名、源数组名和指向源数组最后一个元素后面的元素指针的方法。现在三种方法得到的答案都有误,以下是程序,还请各位大佬指点:
#include<stdio.h>
void copy_arr( double target1[], double source[], int num );
void copy_ptr( double *target2, double *source, int num );
void copy_ptrs( double *target3, double *start, double *end );
void out_put( double *target, int num);
int main(void)
{
double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
double target1[5];
double target2[5];
double target3[5];
copy_arr(target1, source, 5);
copy_ptr(target2, source, 5);
copy_ptrs(target3, source, source + 5);
out_put(target1, 5);
out_put(target2, 5);
out_put(target3, 5);
return 0;
}
void copy_arr( double target1[], double source[], int num )
{
int i;
for(i = 0; i < num; i++)
{
target1[i] = source[i];
}
}
void copy_ptr( double *target2, double *source, int num )
{
int i;
for(i = 0; i < num; i++)
{
*target2 = *source;
*target2++;
*source++;
}
}
void copy_ptrs( double *target3, double *start, double *end )
{
while(*start < *end)
{
*target3 = *start;
*start++;
}
}
void out_put( double *target, int num)
{
int i;
for(i = 0; i < num; i++)
{
printf("%d, ", *target);
*target++;
}
printf("\n");
}