用C语言写一个单词接龙游戏。

//不好意思,写代码的时候看到已经有推荐答案了。.....

# include & ltstdio.h & gt

# include & ltiostream & gt

# include & ltstring.h & gt

# include & ltstdlib.h & gt

# include & ltwindows.h & gt

#定义最大80

char buff[MAX+1];

char first[4];

char last

布尔拼写检查()

{

int p = 0;

while(buff[p]!= 0)

{

if(buff[p]>z ' | | buff[p]& lt;a’)

返回false

p++;

}

返回true

}

布尔语法检查()

{

int len = strlen(first);

if(len == 3)

{

if(strncmp(first,buff,3) == 0)

返回true

else if(strncmp(& amp;first[1],buff,2) == 0)

返回true

else if(strncmp(& amp;first[2],buff,1) == 0)

返回true

}

else if(len == 2)

{

if(strncmp(& amp;first[0],buff,2) == 0)

返回true

else if(strncmp(& amp;first[1],buff,1) == 0)

返回true

}

else if(len == 1)

{

if(strncmp(& amp;first[0],buff,1) == 0)

返回true

}

返回false

}

void getWord()

{

{

Printf("请先输入一个全小写的单词以匹配%s \n ",);

scanf("%s ",buff);

如果(!拼写检查())

{

Printf("拼写错误,请输入一个全小写的单词..........\ n ");

继续;

}

如果(strlen(buff) == 0

{

Printf("请输入一个单词...\ n ");

继续;

}

返回;

}while(真);

}

无效开始()

{

FILE *fp = fopen("D:\\1.txt "," w ");//& lt;-在此更改输出文件的路径。

int len

first[0]= rand()% 26+' a ';

first[1]= 0;

last = rand()% 26+' a ';

printf("a1:%c a2:%c\n ",first[0],last);

while(真)

{

getWord();

如果(!syntaxCheck())

{

Printf("您输入的单词不符合要求,请重新输入......\ n ");

继续;

}

其他

{

fprintf(fp," %s\n ",buff);

len = strlen(buff);

if(buff[len-1] == last)

{

Print("结束% s匹配a2:%c,所以游戏结束\n ",buff,last);

打破;

}

其他

{

if(len & gt;= 3)

strcpy(第一& ampbuff[len-3]);

其他

strcpy(first,buff);

Printf("匹配成功,请继续输入...............................................................................................................................................................

}

}

}

fclose(FP);

}

int main()

{

srand(GetTickCount());

start();

系统(“暂停”);

}