以下问题:让字符串增长输入
我想做一种hang子手游戏(控制台中的所有东西)。 所以我做了一个循环,在游戏结束后会变成13次,玩家松动(如果玩家插入错误的字母,它只会倒数)。 现在,我想向用户显示他已使用哪些字母。所以输出应该是这样的:“你已经使用过:a,b,c,g ...”等等。所以在每次尝试之后,该行都会增长一个字母(当然是输入字母)。 我试过strcpy,但它只会产生随机字母,我从来没有放过,它不会增长,所以我该如何处理?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int main()
{
char word[81], used[14];
int wrong=0, laenge, _, i;
char input;
SetConsoleTitle(" Guess me if u Can! ");
//printf("\n\n spielst du mit einem Freund oder alleine?"); /*for later
//printf(" \n\n [1] alleine"
// " \n\n [2] mit einem Freund"); */
printf("\n\n please insert a word (max. 80 characters): \n\n");
gets(word);
laenge=strlen(word);
printf("\n\n this word has %i characters.\n\n",laenge);
for(i=0; i<13; i++)
{
// for(_=0; _<laenge; _++) /*ignore this this is also for later
// printf(" _");
// printf("\n"); */
gotoxy(10,10);
printf("\n\n please insert a letter now: ");
input=getch();
strcpy(used, &input);
printf("\n\n The following characters are allready used: %c ", used);
if(strchr(word, input)){
printf("\n\n %c is in the word\t\t\t\t\t\t\n\n");
i--;
}
else{
printf("\n\n the letter %c is wrong!\n");
wrong++;
printf(" you have %i try",13-wrong);
}
}
system("cls");
printf("\n\n to many tries.\n\n");
system("Pause");
}
边注:从来没有使用的变量名与'_'开始(他们可能会使用系统变量冲突)。更少一个'_'。 –
这就是为什么我总是使用带有字符串的语言。 –