确保用户的输入与我的程序生成的字符匹配

这是为家庭作业

我正在编写一个简化的拼字游戏,我让我的程序随机生成字符然后用户会尝试从这些生成的字符创建一个单词,然后得到一个分数。 我遇到的问题是确保用户实际使用提供的字符。 我不知道如何处理这个问题。 我不需要任何代码,但提示将被赞赏,甚至链接开始点。 谢谢你的帮助!

编辑 – 大约我的一半程序[创建字母集的部分]

void generate_letter_set(int letter_set[] , int size_let , int num_let) { int arr[N]; const char let[] = {'K','J','X','Q','Z','B','C','M','P','F','H','V','W','Y','G','L','S','U','D','N','R','T','O','A','I','E'}; const int freq[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 6, 6, 6, 8, 9, 9, 12 }; int score[] = { 5, 8, 8, 10, 10, 3, 3, 3, 3, 4, 4, 4, 4, 4, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1}; int index = 0; for(int i = 0 ; i < 26 ; i++) { for(int f = 0 ; f < freq[i]; f++) { arr[index++] = let[i]; //All the 96 letters are stored in let[i] //printf("%c " , let[i]); // Created the letter bank for all the letters } } int letter; printf("Your letters are: "); for(int l = 0; l < 7; l++){ letter = rand() % 97; printf("%c ", arr[letter]); } } 

搜索某些字符的数组有很多种不同的方法。 您需要的基础是一个非常简单的搜索function。

一个简单的解决方案是使用两个嵌套的for循环。 假设让[]是你要检查的’haystack’而word是你的用户输入:

 // Check each letter of word[]... for (int ii = 0; ii <= lengthOfUserInput; ii++) { char characterToValidate = word[ii]; // ... for not existing in let[] for (int jj = 0; jj <= lengthOfStringOfValues; jj++) { if (characterToValidate != let[jj]) } }