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

土豪

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

我想向用户显示他们键入的内容的原因是,以便最终可以作为概述,但是现在我只是想使其正常运行。

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

#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;
}
里尤尔·苏迪尔(Rijul Sudhir)
#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;
}

我希望这就是你想要的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将数组添加到列表并在 C# 中为列表中的每个数组打印数组的每个值

来自分类Dev

在C中打印数组?

来自分类Dev

在C中打印数组

来自分类Dev

打印数组中的字符,然后将光标向下移至C的一行

来自分类Dev

打印数组中的字符,然后将光标向下移至C的一行

来自分类Dev

打印数组中的字符,然后将光标向下移至C的一行

来自分类Dev

打印数组中的字符,然后将光标向下移至C的一行

来自分类Dev

无法使用C将内容正确添加到我的数组中

来自分类Dev

将结构添加到 C 中的动态数组

来自分类Dev

在C中打印数组的值

来自分类Dev

在Visual C ++中打印数组

来自分类Dev

无法在 C 中打印数组值

来自分类Dev

添加到结构的外部数组。(C编程语言)

来自分类Dev

在汇编程序中反向打印数组

来自分类Dev

如何将随机数组的值添加到另一个数组中,然后在计算出现的值的同时显示它们?C ++

来自分类Dev

如何将随机数组的值添加到另一个数组中,然后在计算出现的值的同时显示它们?C ++

来自分类Dev

C#将一个RichTextBoxes数组添加到for循环中的TabPages数组中

来自分类Dev

在特定位置将字符串添加到字符数组中,从而在 C 编程中导致缓冲区溢出

来自分类Dev

读取文件内容,存储在数组中,向数组中添加更多内容,然后将新数组存储在文件中C ++

来自分类Dev

将条件字符添加到 C 中的打印语句

来自分类Dev

在 c 中打印数组元素中的多余 @

来自分类Dev

将标记添加到数组C

来自分类Dev

使用C#将数组添加到HTTP请求URI中的任何方法?

来自分类Dev

如何在C中以定义的长度将char添加到数组的末尾

来自分类Dev

C#将扩展Append方法添加到类型T的类数组中

来自分类Dev

将字符串添加到char数组并在C中以\ 0分隔

来自分类Dev

将索引和指定数字添加到 C++ 中的数组

来自分类Dev

c#如何通过函数将值添加到“公共数组列表”中

来自分类Dev

C#静态成员未添加到数组中

Related 相关文章

  1. 1

    如何将数组添加到列表并在 C# 中为列表中的每个数组打印数组的每个值

  2. 2

    在C中打印数组?

  3. 3

    在C中打印数组

  4. 4

    打印数组中的字符,然后将光标向下移至C的一行

  5. 5

    打印数组中的字符,然后将光标向下移至C的一行

  6. 6

    打印数组中的字符,然后将光标向下移至C的一行

  7. 7

    打印数组中的字符,然后将光标向下移至C的一行

  8. 8

    无法使用C将内容正确添加到我的数组中

  9. 9

    将结构添加到 C 中的动态数组

  10. 10

    在C中打印数组的值

  11. 11

    在Visual C ++中打印数组

  12. 12

    无法在 C 中打印数组值

  13. 13

    添加到结构的外部数组。(C编程语言)

  14. 14

    在汇编程序中反向打印数组

  15. 15

    如何将随机数组的值添加到另一个数组中,然后在计算出现的值的同时显示它们?C ++

  16. 16

    如何将随机数组的值添加到另一个数组中,然后在计算出现的值的同时显示它们?C ++

  17. 17

    C#将一个RichTextBoxes数组添加到for循环中的TabPages数组中

  18. 18

    在特定位置将字符串添加到字符数组中,从而在 C 编程中导致缓冲区溢出

  19. 19

    读取文件内容,存储在数组中,向数组中添加更多内容,然后将新数组存储在文件中C ++

  20. 20

    将条件字符添加到 C 中的打印语句

  21. 21

    在 c 中打印数组元素中的多余 @

  22. 22

    将标记添加到数组C

  23. 23

    使用C#将数组添加到HTTP请求URI中的任何方法?

  24. 24

    如何在C中以定义的长度将char添加到数组的末尾

  25. 25

    C#将扩展Append方法添加到类型T的类数组中

  26. 26

    将字符串添加到char数组并在C中以\ 0分隔

  27. 27

    将索引和指定数字添加到 C++ 中的数组

  28. 28

    c#如何通过函数将值添加到“公共数组列表”中

  29. 29

    C#静态成员未添加到数组中

热门标签

归档