我现在正在读这样的内容:
while (fscanf(in, "%c", infile) != EOF)
{
ch = *infile;
count++;
ascii[ch]++;
}
制作我的频率表:
void frequency ()
{
unsigned long long i;
for (i = 0; i < 255; i++)
{
if (ascii[i] != 0)
{
uniqueLetters++;
if (i < 33)
{
printf("=%llu\t%lu\n", i, ascii[i]);
}
else if (i > 126)
{
printf("=%llu\t%lu\n", i, ascii[i]);
}
else printf("%c\t%lu\n", (int)(i), ascii[i]);
}
}
printf("unique letters: %lu\n", uniqueLetters);
}
(这是一个霍夫曼编码项目,当我尝试读取整个文件时,我完全错过126以上的任何内容......)
答案 0 :(得分:1)
尝试fgetc
:
FILE * fp = fopen(filename, "r");
int ch; // return type of fgetc is int
while ((ch = fgetc(fp)) != EOF)
ascii[ch]++;