私は、cca140000の単語を含む辞書の単語の開始文字の頻度を数えようとしています。頻度を配列カウントに保存します。文字aの場合はcount[0]、文字bの場合はカウント[1]です...ただし、配列カウントを合計すると、値は単語の総数と等しくなりません。辞書で。辞書のサイズを95137に減らすと、数値は等しくなりますが、辞書の単語数が95137を超えると、count[0]からcount[4]までの値が突然非常に大きくなることがわかりました。理由はわかりません。コードは次のとおりです。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
FILE *fp = fopen("testdic.txt", "r");
int count[26];
char buffer[30];
for (int i = 0; i < 26; i++)
count[i] = 0;
int total = 0;
while (1)
{
fscanf(fp, "%s", buffer);
if (feof(fp))
break;
count[buffer[0]-97] ++;
total++;
if (count[0] > total) // I used this to find out where the jump occurs
break;
}
printf("%d ", i);
for (int i = 0; i < 26; i++)
printf("%d " , count[i]);
}