You are displaying the contents of your array here:
1 2 3 4
for (int i = 0; i < numWords; i++)
{
cout << showWords[i];
}
if you post your entire code i can test it to see if it works myself.
Also is this array suppose to be dynamically allocated? Because if the user enters a number bigger than 100 you'll have more words than array elements to store them in.
//Function Prototypes
int sizeOfArray(int);
void DisplayChars(char [][15], int);
int main()
{
int size, numWords, i, j, k;
char showChars[15][15], showWords[20]
cout << "How many rows and columns: ";
cin >> size;
while (sizeOfArray(size) != 1)
{
cout << "Please enter a valid range between 1 and 15. " << endl;
cin >> size;
}
cout << "Enter the characters, " << size << " per row: ";
cout << endl;
for (i = 0; i < size; i++)
{
for (j = 0; j < size; j++)
{
cin >> showChars[i][j];
}
}
cout << endl;
cout << "How many words should i look for : ";
cin >> numWords;
cout << "\nEnter the " << numWords << " words: " << endl;
for (k = 0; k <= numWords; k++)
{
cin >> showWords[k];
}
cout << endl;
cout << "HIDDEN WORDS PUZZLE " << endl << "****************" << endl;
DisplayChars(showChars, size);
for (int i = 0; i < numWords; i++)
{
cout << showWords[i];
}
system("PAUSE");
return 0;
}
/**
* Function <code>sizeOfArray</code> Verifies that the size of the 2D array is in
* the correct range.
* <BR>
* @param Size The size of the 2D array.
*/
int sizeOfArray(int Size)
{
while (Size > 0 && Size <= 15)
{
return 1;
}
return 0;
}
/**
* Function <code>DisplayChars</code> Displays the characters of the 2D array entered by
* the user.
* <BR>
* @param Show The 2D Array of characters to be filled in.
* @param n The size of the 2D array.
*/
void DisplayChars(char Show[][15], int n)
{
int i, j;
sizeOfArray(n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
cout << Show[i][j];
}
cout << endl;
}
return;
}