C语⾔实现读取⽂件,并统计每个字符出现的个数/*****************
实现读取⽂件,并统计每个字符出现的个数
*****************/
#include <stdio.h>
#include <stdlib.h>
unsigned long file_size;
unsigned int frequency_count[512];
人教版初二英语下册
FILE* infilepointer;
void get_frequency_count ()
{
for (unsigned int i = 0; i < file_size; i++)
hepa
{
frequency_count[getc(infilepointer)]++;
//getc (infilepointer)从⽂件指针指向的⽂件读⼊⼀个字符
}
}
bool func(const char* infilename)
{completed是什么意思
ridebackif(( infilepointer = fopen(infilename, "rb") ) != NULL)
{
cet 4fek( infilepointer, 0L, 2);//将⽂件位置指针指向⽂件末尾
file_size = (unsigned long) ftell(infilepointer);
fek( infilepointer, 0L, 0);
get_frequency_count ();
fclo (infilepointer);
hrc
return 1;
}
el
{
printf("Error! can't open %s",infilename);
return 0;
}
}
int main()
passbook{
func("C:\\Urs\\Pacer95\\Desktop\\12.txt");
长脸男生发型设计>留学日本中介
printf("%d,",frequency_count[48]);
consulate//这⾥48是0的ascii值,即打印出12.txt⾥0字符的个数,想打印哪个字符,改成对应ascii
}
<⾥的内容
统计出0字符的个数,如图