Originally Posted by
Babkockdood
target2 is an array?
Yeah. I declare it: int target2[5];
Here's my code:
Code:
#include <stdio.h>
void copy_arr(const double source[], double target[], int COLS);
void copy_ptr(const double source[], double target[], int COLS);
int main(void)
{
int i;
double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
double target1[5], target2[5];
copy_arr(source, target1, 5);
copy_ptr(source, target2, 5);
printf("source target 1 target 2\n");
for(i = 0; i<5; i++)
{
printf("%.1lf %.1lf %.1lf \n", source[i], target1[i], *target2++); // *target2++ gives compile error.
}
return 0;
}
void copy_arr(const double source[], double target[], int COLS)
{
int i;
for (i=0; i < COLS; i++)
target[i] = source[i];
}
void copy_ptr(const double source[], double target[], int COLS)
{
int i;
for (i=0; i<COLS; i++)
{
*target++ = *source++;
}
}