C语言疯狂打字游戏:提升打字速度,挑战你的反应力!
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define _CRT_SECURE_NO_WARNINGS #define MAX_WORDS 10 #define MAX_WORD_LENGTH 50 char words[MAX_WORDS][MAX_WORD_LENGTH] = { "apple", "banana", "orange", "watermelon", "strawberry", "pineapple", "grapefruit", "kiwi", "blueberry", "mango" }; int main() { srand(time(0)); printf("欢迎来到疯狂打字游戏!\n"); printf("你将会看到一系列乱序的字母,你需要输入对应的正确单词。\n"); printf("输入"exit"可以退出游戏。\n");
int score = 0;
int round = 1;
while (1) {
printf("\n第 %d 轮:\n", round);
// 随机选择一个单词
int randomIndex = rand() % MAX_WORDS;
char word[MAX_WORD_LENGTH];
strcpy_s(word, words[randomIndex]);
// 乱序字母
int wordLength = strlen(word);
for (int i = 0; i < wordLength; i++) {
int randomIndex = rand() % wordLength;
char temp = word[i];
word[i] = word[randomIndex];
word[randomIndex] = temp;
}
// 显示乱序字母
printf("乱序字母:%s\n", word);
// 接受用户输入
char input[MAX_WORD_LENGTH];
printf("请输入单词:");
scanf("%s", &input);
printf("6");
// 检查退出条件
if (strcmp(input, "exit") == 0) {
break;
}
// 检查答案
if (strcmp(input, words[randomIndex]) == 0) {
printf("回答正确!\n");
score += 10;
}
else {
printf("回答错误!正确答案是:%s\n", words[randomIndex]);
}
round++;
}
printf("\n游戏结束!你的得分是:%d\n", score);
return 0;
}为什么运行不出来,错误是0xFEFEFEFE 处有未经处理的异常(在 Project7.exe 中): 0xC00001A5: 检测到无效的异常处理程序例程。
内容:这个错误通常是由于使用了不兼容的编译器或编译选项导致的。你可以尝试以下解决方法:
-
确保你的编译器版本是兼容的。如果你使用的是较旧的编译器,尝试升级到较新的版本。
-
确保你的编译选项正确设置。如果你使用的是Visual Studio,可以尝试在项目属性中修改编译选项,例如将优化等级调整为较低的级别。
-
检查代码中是否存在其他错误。有时,其他错误可能会导致异常。
-
尝试在不同的开发环境中编译和运行代码,例如使用Code::Blocks或Dev-C++等。
如果以上方法都无效,那么可能是你的代码存在某些特定问题。你可以尝试逐步调试代码,找出引起异常的具体位置,或者尝试使用其他方法实现相同的功能。
原文地址: https://www.cveoy.top/t/topic/pKI3 著作权归作者所有。请勿转载和采集!