This is a code where the user has a 'Word Search Game', the user is has a menu where he can choose to do a new puzzle and then show it and try to work it out. The user needs to enter 4 words and those inputted words need to be shown in a matrix for other users to find and play. My problem with my code is when the user has to enter 4 words, the system crashes and exists the program. Also how can i put those words which are written by the user inside the matrix?
Code below:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
srand((unsigned)time(NULL));
char Matrix[10][10];
char Location[4][4];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Matrix[i][j] = (rand() % (91 - 65)) + 65;
}
}
int menuChoice;
do
{
system("cls");
puts("WORD SEARCH GAME PUZZLE");
puts("-----------------------");
puts("1. New Puzzle");
puts("2. Show Puzzle");
puts("3. Exit");
puts("-----------------------");
puts("Select your choice: ");
scanf_s("%d", &menuChoice);
switch (menuChoice)
{
case 1: newPuzzle(); break;
case 2: showPuzzle(Matrix); break;
}
} while (menuChoice != 3);
return 0;
}
int newPuzzle()
{
int i;
char word[7];
system("cls");
printf("Enter 4 words of your choice to be entered in the puzzle: \n");
for (i = 0; i < 4; i++)
{
printf("Enter word %d: ", i + 1);
scanf_s("%s", &word);
}
return 0;
}
int showPuzzle(char m[10][10])
{
system("cls");
printf(" ");
char c;
for (c = 'A'; c <= 'J'; ++c)
{
printf("%c ", c);
}
printf("\n\n");
for (int i = 0; i < 10; i++) {
printf("%d ", i);
for (int j = 0; j < 10; j++) {
printf("%c ", m[i][j]);
}
printf("\n");
}
getch();
return 0;
}