//囧,代码写好回来一看居然已经有推荐答案了.
#include
#include
#include
#include
#include
#define MAX 80
char buff[MAX+1];
char first[4];
char last;
bool spellCheck()
{
int p = 0;
while(buff[p] != 0)
{
if(buff[p] > 'z'||buff[p] < 'a')
return false;
p++;
}
return true;
}
bool syntaxCheck()
{
int len = strlen(first);
if(len == 3)
{
if(strncmp(first,buff,3) == 0)
return true;
else if(strncmp(&first[1],buff,2) == 0)
return true;
else if(strncmp(&first[2],buff,1) == 0)
return true;
}
else if(len == 2)
{
if(strncmp(&first[0],buff,2) == 0)
return true;
else if(strncmp(&first[1],buff,1) == 0)
return true;
}
else if(len == 1)
{
if(strncmp(&first[0],buff,1) == 0)
return true;
}
return false;
}
void getWord()
{
do
{
printf("请输入一个全小写的单词,和%s匹配\n",first);
scanf("%s",buff);
if(!spellCheck())
{
printf("拼写错误,请输入一个全小写的单词.\n");
continue;
}
if(strlen(buff) == 0)
{
printf("请输入一个单词.\n");
continue;
}
return;
}while(true);
}
void start()
{
FILE *fp = fopen("D:\\1.txt","w");//= 3)
strcpy(first,&buff[len-3]);
else
strcpy(first,buff);
printf("匹配成功,请继续输入.\n");
}
}
}
fclose(fp);
}
int main()
{
srand(GetTickCount());
start();
system("pause");
}
再问: 程序还是很不错的,但是为了能够对单词(或词组)的正确性做出判断,程序需要维护一本英文单词词典。判断单词(或词组)的正确性,就是在该词典中查找相应的单词(或词组),找到则正确,找不到则错误。另外,为保证游戏过程中玩家输入的单词(或词组)有较高的有效性,还应注意英文单词词典的含词量要足够大。而且请给程序加些注释,本人菜鸟,不怎么看得懂,谢谢了。
再答: 代码长度超过限制了 所以传115网盘 字典文件 http://115.com/file/dptyfm5e#dictionary.txt 代码 http://115.com/file/c25bul6h#code.txt