// ex_ch10_8.c -- VLA based copying
#include <stdio.h>
#define ROWS 3
#define COLS 5

void copy_arr(int rows, int cols, const double source[rows][cols],
	      double dest[rows][cols]);
void show_arr(int rows, int cols, const double arr[rows][cols]);

int main(void)
{
	const double source[ROWS][COLS] = {
		{1.1, 2.2, 3.3, 4.4, 5.5},
		{2.1, 3.2, 4.3, 5.4, 6.5},
		{3.1, 4.2, 5.3, 6.4, 7.5},
	};
	double target[ROWS][COLS];

	printf("Orininal array:\n");
	show_arr(ROWS, COLS, source);
	copy_arr(ROWS, COLS, source, target);
	printf("(VLA) Copied array:\n");
	show_arr(ROWS, COLS, target);
	
	return 0;
}

void show_arr(int rows, int cols, const double arr[rows][cols])
{
	int r, c;
	
	for (r = 0; r < rows; r++)
	{
		for (c = 0; c < cols; c++)
			printf("%.1f  ", arr[r][c]);
		putchar('\n');
	}
}

void copy_arr(int rows, int cols, const double source[rows][cols],
	      double dest[rows][cols])
{
	int r, c;
	
	for (r = 0; r < rows; r++)
	{
		for (c = 0; c < cols; c++)
			dest[r][c] = source[r][c];
	}
}
