我已经制作了一个拼写游戏,现在我想在其中附加一个字典文件,这个游戏会检查拼写并返回拼写是否正确。
#include<stdio.h>
#include<string.h>
#include <time.h>
#include <stdlib.h>
int printRandoms(int lower, int upper, int count);
int main()
{
printf("\n Hello !\" Welcome to Boggle game. \" \n");
printf(" \n Start Making as many Words as you can. \n");
printf("\n Board number>> ");
char arr_1[4][4]= {{'D','G','H','I'},{'K','L','P','S'},{'Y','E','U','T'},{'E','O','R','N'}};
char arr_2[4][4]= {{'T','A','P','O'},{'E','N','E','R'},{'D','S','T','A'},{'I','G','H','C'}};
char arr_3[4][4]= {{'E','I','L','E'},{'Z','A','B','N'},{'S','V','O','D'},{'T','E','R','A'}};
char arr_4[4][4]= {{'H','D','E','I'},{'N','A','R','F'},{'S','O','P','U'},{'W','P','Y','L'}};
char arr_5[4][4]= {{'F','B','L','P'},{'R','I','E','A'},{'G','M','N','D'},{'H','T','S','U'}};
char arr_6[4][4]= {{'A','R','K','E'},{'L','O','T','N'},{'S','V','I','D'},{'P','E','B','A'}};
char arr_7[4][4]= {{'M','A','P','O'},{'E','T','E','R'},{'D','E','N','I'},{'L','D','H','C'}};
char arr_8[4][4]= {{'J','U','O','K'},{'A','R','K','E'},{'S','T','N','R'},{'P','E','I','T'}};
char arr_9[4][4]= {{'G','I','L','B'},{'A','D','E','R'},{'N','V','W','S'},{'B','E','I','J'}};
char arr_10[4][4]={{'E','R','T','E'},{'N','I','A','N'},{'S','P','F','V'},{'O','L','E','A'}};
srand(time(NULL)); // Initialization, should only be called once.
int number = printRandoms(1,10,1);
printf("%c\n",number);
switch (number)
{
case 1:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_1[i][j]);
}
printf("|\n------------------\n");
}
break;
case 2:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_2[i][j]);
}
printf("|\n------------------\n");
}
break;
case 3:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_3[i][j]);
}
printf("|\n------------------\n");
}
break;
case 4:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_4[i][j]);
}
printf("|\n------------------\n");
}
break;
case 5:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_5[i][j]);
}
printf("|\n------------------\n");
}
break;
case 6:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_6[i][j]);
}
printf("|\n------------------\n");
}
break;
case 7:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_7[i][j]);
}
printf("|\n------------------\n");
}
break;
case 8:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_8[i][j]);
}
printf("|\n------------------\n");
}
break;
case 9:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_9[i][j]);
}
printf("|\n------------------\n");
}
break;
case 10:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
printf("| %c ", arr_10[i][j]);
}
printf("|\n------------------\n");
}
break;
default:
printf("invalid ");
break;
}
return 0;
}
int printRandoms(int lower, int upper, int count) {
int i;
int num;
for (i = 0; i < count; i++) {
num = (rand() %
(upper - lower + 1)) + lower;
printf("%d\n ", num);
}
return num;
}
这是我粘贴的完整游戏代码。并请指导我如何做到这一点,我只是在学习。