// array2.cpp  -- Playing with two dimensional arrays

#include <iostream>


enum {NAMESIZE=20};

// Print out the first n names of a
void printNames(char a[][NAMESIZE], int n)
{
	for (int row=0; row<n; row++)
	{
		for (int clmn=0; a[row][clmn] != '\0'; clmn++)
		{
			cout << a[row][clmn];
		}
		cout << endl;
	}
}

// Print out the first n names of a
void printNames(char *a[], int n)
{
	for (int k=0; k<n; k++)
	{
		cout << a[k] << endl;
	}
}

void main(void)
{
	char names1[][NAMESIZE] = {"smith", "jones", "samuels", "gumb"};
	char *names2[] = {"smith", "jones", "samuels", "gumb"};

	cout << "The size of names1 is " << sizeof(names1) << endl;
	cout << "The size of names2 is " << sizeof(names2) << endl;


	cout << endl << "Printing out: char names1[][NAMESIZE]" << endl;
	printNames(names1, 4);

	cout << endl << "Printing out: char *names[]" << endl;
	printNames(names2, 4);

	cout << endl << "Printing out: names1[row]" << endl;
	for (int row=0; row < 4; row++)
	{
		cout << names1[row] << endl;
	}

	cout << endl << "Printing out: names2[row]" << endl;
	for (int row=0; row < 4; row++)
	{
		cout << names2[row] << endl;
	}

	names1[2][2] = 'X'; // Just to see if it is legal
	names2[2][2] = 'X'; // Just to see if it is legal
}

/* The output is
The size of names1 is 80
The size of names2 is 16

Printing out: char names1[][NAMESIZE]
smith
jones
samuels
gumb

Printing out: char *names[]
smith
jones
samuels
gumb

Printing out: names1[row]
smith
jones
samuels
gumb

Printing out: names2[row]
smith
jones
samuels
gumb
*/
