gpt4 book ai didi

调用方法C

转载 作者:行者123 更新时间:2023-11-30 19:16:02 24 4
gpt4 key购买 nike

在我的主方法中调用方法时遇到一些问题。我只是想从“init”方法中的数组中随机获取一个单词,找到它的长度,然后打印所有信息。 (生成的随机数,也相关的单词及其长度)。刚刚开始使用 C,感谢所有帮助。

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "hangman.h"

void init(char* word);


int main(void)
{
char word[MAX_WORD_LEN + 1];
unsigned wrongGuesses = 0;
int guessedLetters[ALPHABET_SIZE] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};


init();



return EXIT_SUCCESS;
}



void init(char* word)
{
const char* words[NUM_WORDS] = {
"array", "auto", "break", "case", "cast",
"character", "comment", "compiler", "constant", "continue",
"default", "double", "dynamic", "else", "enum",
"expression", "extern", "file", "float", "function",
"goto", "heap", "identifier", "library", "linker",
"long", "macro", "operand", "operator", "pointer",
"prototype", "recursion", "register", "return", "short",
"signed", "sizeof", "stack", "statement", "static",
"string", "struct", "switch", "typedef", "union",
"unsigned", "variable", "void", "volatile", "while"
};

srand(time(NULL));
int randomNumber;
randomNumber = rand() %51;
printf("%d\n", randomNumber);
int wordLength = strlen(words[randomNumber]);
printf("%d %s\n", wordLength, words[randomNumber]);
}

最佳答案

您已将 init 声明为带有参数 char* 的函数,但在不带参数的情况下调用它。

关于调用方法C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31228449/

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