Declaring the functions like this
Code:
void copy_arr(int rows, int cols, double arr[][5]);
void copy_prnt(int rows, int cols, double tgt[][5]);
and using %lf instead of %f for the scanf() (because you're reading into a double, not a float) works.
You can't use a previous parameter to specify the size of an array in the parameter list, unfortunately. It has to be a constant.
Note that double tgt[3][5] would work as well, or double (*tgt)[5].
Here's the complete code:
Code:
#include <stdio.h>
void copy_arr(int rows, int cols, double arr[][5]);
void copy_prnt(int rows, int cols, double tgt[][5]);
int main(void)
{
double orig[3][5];
copy_arr(3, 5, orig);
copy_prnt(3, 5, orig);
return 0;
}
void copy_arr(int rows, int cols, double arr[][5])
{
int i;
for (i = 0; i < rows; i++)
{
printf("Enter five values:\n");
scanf("%lf %lf %lf %lf %lf", &arr[i][0], &arr[i][1], &arr[i][2], &arr[i][3], &arr[i][4]);
}
}
void copy_prnt(int rows, int cols, double tgt[][5])
{
int i, j;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
printf("%.2f ", tgt[i][j]);
printf("\n");
}
}
Input/output:
Code:
Enter five values:
1 2 3 4 5
Enter five values:
6 7 8 9 10
Enter five values:
11 12 13 14 15
1.00 2.00 3.00 4.00 5.00
6.00 7.00 8.00 9.00 10.00
11.00 12.00 13.00 14.00 15.00