gpt4 book ai didi

C 编程 - 将一个单词添加到数组中,然后打印数组中的内容

转载 作者:行者123 更新时间:2023-11-30 17:01:46 25 4
gpt4 key购买 nike

我目前正在尝试用 C 语言创建一个小游戏,并希望制作一个小原型(prototype),它会打印一个随机单词,让用户键入该单词,然后它会向他们显示他们如何键入它,然后它会向用户展示应如何键入。

我想向用户展示他们输入的内容的原因是这样最后它们可以成为一个概述,但现在我只想让它工作。

目前,它不显示用户输入的内容,而是显示数字,我认为这与我放置单词的数组有关,但我不知道。我怎样才能让它打印数组中的单词?代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>

void main()
{
char *words[] = {"sausage","blubber","pencil","cloud","moon","water","computer","school","network","hammer","walking","violently","mediocre","literature","chair","two","window","cords","musical","zebra","xylophone","penguin","home","dog","final","ink","teacher","fun","website","banana","uncle","softly","mega","ten","awesome","attatch","blue","internet","bottle","tight","zone","tomato","prison","hydro","cleaning","telivision","send","frog","cup","book","zooming","falling","evily","gamer","lid","juice","moniter","captain","bonding","loudly","thudding","guitar","shaving","hair","soccer","water","racket","table","late","media","desktop","flipper","club","flying","smooth","monster","purple","guardian","bold","hyperlink","presentation","world","national","comment","element","magic","lion","sand","crust","toast","jam","hunter","forest","foraging","silently","tawesomated","joshing","pong","RANDOM","WORD"};
char *questions[] = {"sausage1","blubber1","pencil1","cloud1","moon1","water1","computer1","school1","network1","hammer1","walking1","violently1","mediocre1","literature1","chair1","two1","window1","cords1","musical1","zebra1","xylophone1","penguin1","home1","dog1","final1","ink1","teacher1","fun1","website1","banana1","uncle1","softly1","mega1","ten1","awesome1","attatch1","blue1","internet1","bottle1","tight1","zone1","tomato1","prison1","hydro1","cleaning1","telivision1","send1","frog1","cup1","book1","zooming1","falling1","evily1","gamer1","lid1","juice1","moniter1","captain1","bonding1","loudly1","thudding1","guitar1","shaving1","hair1","soccer1","water1","racket1","table1","late1","media1","desktop1","flipper1","club1","flying1","smooth1","monster1","purple1","guardian1","bold1","hyperlink1","presentation1","world1","national1","comment1","element1","magic1","lion1","sand1","crust1","toast1","jam1","hunter1","forest1","foraging1","silently1","tawesomated1","joshing1","pong1","RANDOM1","WORD1"};
char answer[255] = "";

int word;
int vec[20] = { 0 };
int i, j;
int x=0;
srand(time(NULL));

do{
for (i = 0; i < 20; i++) {
int okay = 0;

while (!okay) {
vec[i] = rand() % 100 + 1;
okay = 1;

for (j = 0; j < i; j++) {
if (vec[i] == vec[j]) okay = 0;
}
}

word=vec[i];

printf("%s\n",questions[word]); //print a word
scanf("%255s",answer);// wait for the user to type the word
printf("%s\n",answer[x]);// show what the user typed

printf("%s\n\n",words[word]);// show how they should of typed it

}
}while (x<20,x++);

return 0;
}

最佳答案

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>

void main()
{
char *words[] = {"sausage","blubber","pencil","cloud","moon","water","computer","school","network","hammer","walking","violently","mediocre","literature","chair","two","window","cords","musical","zebra","xylophone","penguin","home","dog","final","ink","teacher","fun","website","banana","uncle","softly","mega","ten","awesome","attatch","blue","internet","bottle","tight","zone","tomato","prison","hydro","cleaning","telivision","send","frog","cup","book","zooming","falling","evily","gamer","lid","juice","moniter","captain","bonding","loudly","thudding","guitar","shaving","hair","soccer","water","racket","table","late","media","desktop","flipper","club","flying","smooth","monster","purple","guardian","bold","hyperlink","presentation","world","national","comment","element","magic","lion","sand","crust","toast","jam","hunter","forest","foraging","silently","tawesomated","joshing","pong","RANDOM","WORD"};
char *questions[] = {"sausage1","blubber1","pencil1","cloud1","moon1","water1","computer1","school1","network1","hammer1","walking1","violently1","mediocre1","literature1","chair1","two1","window1","cords1","musical1","zebra1","xylophone1","penguin1","home1","dog1","final1","ink1","teacher1","fun1","website1","banana1","uncle1","softly1","mega1","ten1","awesome1","attatch1","blue1","internet1","bottle1","tight1","zone1","tomato1","prison1","hydro1","cleaning1","telivision1","send1","frog1","cup1","book1","zooming1","falling1","evily1","gamer1","lid1","juice1","moniter1","captain1","bonding1","loudly1","thudding1","guitar1","shaving1","hair1","soccer1","water1","racket1","table1","late1","media1","desktop1","flipper1","club1","flying1","smooth1","monster1","purple1","guardian1","bold1","hyperlink1","presentation1","world1","national1","comment1","element1","magic1","lion1","sand1","crust1","toast1","jam1","hunter1","forest1","foraging1","silently1","tawesomated1","joshing1","pong1","RANDOM1","WORD1"};
char answer[20][255];

int word;
int vec[20] = { 0 };
int i, j;
int x=0;
srand(time(NULL));

do{
for (i = 0; i < 20; i++) {
int okay = 0;

while (!okay) {
vec[i] = rand() % 100 + 1;
okay = 1;

for (j = 0; j < i; j++) {
if (vec[i] == vec[j]) okay = 0;
}
}

word=vec[i];

printf("%s\n",questions[word]); //print a word
scanf("%s",answer[i]);// wait for the user to type the word
printf("%s\n",answer[i]);// show what the user typed

printf("%s\n\n",words[word]);// show how they should of typed it

}
}while (x<20,x++);

return 0;
}

我希望这就是你想要的。

关于C 编程 - 将一个单词添加到数组中,然后打印数组中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36824339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com