0

テキストファイルの文字列内に特定の単語が何回出現するかを検索してカウントするこのプログラムがあります。

for(int i = 0; i < file_string_lenght - word_search_lenght; i++)
    {
        found = 1;
        for(int j = 0; j < word_search_lenght; j++)
        {
            if(file_string[i + j] != word_search[j])
            {
                found = 0;
                break;
            }
        }
        if(found == 1)
        {   //the question on the start of the program, whether user wants to print each found word's location
            if(strcmp(response, "yes") == 0){
                printf("'%s' found at index: %d \n", word_search, i);
            }
            count_of_word_search += 1;
        }
    }
    if(pocet == 0){
        printf("The word '%s' was not found in the file.", word_search);
        printf("\n\n");
        system("pause");

        return 0;
    }
    printf("\nNumber of '%s' in the file: %d", word_search, count_of_word_search);

たとえば、「今日」または「昨日」にある場合、「日」という単語はカウントされません。検索している単語と残りの文字列の間のドット、列、またはスペースを認識する必要があることを理解しています。しかし、これをこの種のアルゴリズムに実装する方法はまだわかっていません。手伝ってくれてありがとう

4

0 に答える 0