gpt4 book ai didi

C - 查找每个单词在输入中出现的次数

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

我的任务是创建一个函数

Prints a table indicating the number of occurrences of each different words in the text in the same order in which they appear

我正在使用 gets() 读取字符串,这是一个对字符串中的每个单词进行标记并将其存储在二维数组中的函数,并且需要帮助弄清楚如何制作一个分析数组是否有重复项的方法。

这是标记器函数:

void tokeniz(char *array)
{
char words[arraySize][arraySize] = { NULL };

const char s[2] = " ";
char *token;
int i = 0;

token = strtok(array, s);

while (token != NULL)
{
strcpy(words[i], token);
token = strtok(NULL, s);
i++;
}
wotable(words);
}

在程序的前面,我有一个函数来计算每个字符在字符串中出现的次数(预标记化)。我可以重新调整其中一些代码的用途吗?

    void   alpha(char *array)
{
char character = 'a';
int numberOf = 0, tcc = 0;

for (character = 'a'; character <= 'z'; character++)
{
tcc = (tcc + numberOf);
numberOf = 0;
for (int i = 0; i < arraySize; i++)
if (*(array + i) == character)
numberOf++;
if (numberOf != 0)
printf("\nNumber of %c's:\t\t%d\n", character, numberOf);
}
printf("\nTotal character count:\t%d\n\n- - - - - - - - - - - - - -", tcc);
}

最佳答案

不,您将无法重新调整其中某些代码的用途。

关于C - 查找每个单词在输入中出现的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013220/

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