gpt4 book ai didi

c - C 中的唯一字计数器

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

我正在用 C 编写一个小程序,它应该计算 c 中的唯一单词。为此,我有一本单词簿来存储所有找到的单词。通常,它应该只放入尚未包含在其中的单词,但它会不断输入所有书面单词。我该如何解决这个问题以及如何删除我的单词本“woerterbuch”中的所有空白部分?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


char lies_wort(char *Text);
char suche_wort(char *wort);
char neues_wort(char *wort);
char *woerterbuch[1000];

int main(void)
{
char Text[1000];
printf("Bitte Text eingeben : \n") ;
fgets (Text, 1000, stdin);
lies_wort(Text);
int i;
for(i=0;i<1000;i++){
printf("woerterbuch :%s\n",woerterbuch[i]);}
}
char lies_wort(char *Text){
char *wort;
int i=1;
wort = strtok(Text, " ,.!?;:");
while(wort != NULL) {
suche_wort(wort);
printf("gefunden %d: %s\n", i++, wort);
wort = strtok(NULL, " ,.!?;:");}
}
char suche_wort(char *wort)
{
int i;
for (i = 0; i>1000; i++){
if (!strcmp(woerterbuch[i],wort)){return 0;}}
neues_wort(wort);
return 0;
}
char neues_wort(char *wort)
{
int i;
for (i=0; i<1000; i++){
if(woerterbuch[i]==0){
woerterbuch[i]=wort;
return 0;}}
}

为了测试这个程序只是打印“woerterbuch”中的所有单词,这样我就可以检查它是否正常工作。

最佳答案

suche_wort

for (i = 0; i>1000; i++)

应该是

for (i = 0; i<1000; i++)

你的循环每次都会立即终止。

关于c - C 中的唯一字计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41663771/

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