i think i didn't make my questions clear..... Here's the question in chapter 10..problem 2....
Problem 2:
Write a program that initializes an array-of-double and then copies the contents of the array into two other arrays. (All three arrays should be declared in the main program.) To make the first copy, use a function with array notation. To make the second copy, use a function with pointer notation and pointer incrementing. Have each function take as arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations:
Code:
double source[5] = {1.1, 2.2, 3.3., 4.4, 5.5};
double target1[5];
double target2[5];
copy_arr(source, target1, 5);
copy_ptr(source, target1, 5);
-------
and here's my answer to that problem...
Code:
#include <stdio.h>
void show(double *,int);
void copy_ptr(double *, double *, int);
void copy_arr(double [],double [], int);
int main(void)
{
double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
double target1[5];
double target2[5];
copy_arr(source,target1,5);
copy_ptr(source, target1, 5);
show(source,5);
show(target1,5);
show(target1,5);
return 0;
}
void copy_arr(double ar[],double b[], int a)
{
int c;
for(c=0;c<a;c++)
b[c]=ar[c];
}
void copy_ptr(double *ar, double *b, int a)
{
int c;
for(c=0;c<a;c++)
*(ar+c)=*(b+c);
}
void show(double *ar, int a)
{
int c;
for(c=0;c<a;c++)
printf("%g\t",*(ar+c));
printf("\n");
}
-------
no problem in that question...it is very simple...but on problem 6....here it goes
Write a program that initializes a two-dimensional array-of-double and uses one of the copy functions from exercise 2 to copy it to a second two-dimensional array. (Because a two-dimensional array is an array of arrays, a one-dimensional copy function can be used with each subarray.)
to use one of the function of my answer in problem 2....like for example this kind of function that i've arrived in problem 2....
-------------
Code:
void copy_arr(double ar[][], double *, int);
<---in this line i change the 1st argument because we gonna pass a 2-dimensional array....but it would error in the 2nd argument because of the compiler warning...saying that the argument is not right to pass an 2-dimensional array on a 1 dimensional array......did you get my question???thnx for replying