diff --git a/hzInFile.cpp b/hzInFile.cpp deleted file mode 100644 index 1ae7c00..0000000 --- a/hzInFile.cpp +++ /dev/null @@ -1,46 +0,0 @@ -void hzInFile (CString FileName) -{ - FILE *in; - unsigned char c1, c2; - int id; - in=fopen((const char *)FileName, "rb"); - if(in==NULL) - { - AfxMessageBox("无法打开输入文件!"); - return; - } - while (!feof (in)) - { - c1=(unsigned char ) fgetc(in); // 转换为无符号字符 - if(c1<128) - { - continue; // 不处理单字节西文字符 - } - else if(c1<176) - { - c2=fgetc(in); - continue; - } // 也不处理非汉字字符,但要多读一个字节 - else - { - c2=(unsigned char ) fgetc(in); // 读入汉字的第二个字节 - id=HZ_ID(c1,c2); // 计算该汉字的下标 - HZFreq[id]++; // 给该汉字的频度加1 - } - } - fclose(in); - return; -} -void OnSingleHz() -{ - // 单字字频统计 - for(int i=0; i0) - fprintf(outFile, "%c%c\t%d\n", id/94+176, id%94+161, HZFreq[id]); - fclose(outFile); - return; -} \ No newline at end of file diff --git a/hzInFile/hzInFile.cpp b/hzInFile/hzInFile.cpp new file mode 100644 index 0000000..55009b3 --- /dev/null +++ b/hzInFile/hzInFile.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#define HZ_NUM 6768 +#define HZ_ID(c1,c2) ((c1)-176)*94 + ((c2)-161) + // 计算汉字下标的宏 +int HZFreq[HZ_NUM]; + +void hzInFile (char*FileName) +{ + // 单字字频统计 + int i; + for(i=0; i0) + fprintf(outFile, "%c%c\t%d\n", id/94+176, id%94+161, HZFreq[id]); + fclose(outFile); + return; +} +/* + int main(int argc, char* argv[]) + { + int i; + for (i = 0; i>i; + if(argc==2) + { + char *fileName=argv[1]; + hzInFile(fileName); + } + cout<<"任务完成。"< -void print_GB2312() -{ - FILE *outFile; - unsigned char i,j; - outFile=fopen("gb2312-80.txt","wt"); - for(i=161; i<255; i++) - { - for(j=161; j<255; j++) - { - fprintf(outFile,"%c%c,%d,%d\n",i,j,i,j); - } - } - fclose(outFile); -} +#include +void print_GB2312() +{ + FILE *outFile; + unsigned char i,j; + outFile=fopen("gb2312-80.txt","wt"); + for(i=161; i<255; i++) + { + for(j=161; j<255; j++) + { + fprintf(outFile,"%c%c,%d,%d\n",i,j,i,j); + } + } + fclose(outFile); +} +/* +void main() +{ + print_GB2312(); +}*/ \ No newline at end of file diff --git a/print_GB2312/print_GB2312.exe b/print_GB2312/print_GB2312.exe new file mode 100644 index 0000000..6fe581b Binary files /dev/null and b/print_GB2312/print_GB2312.exe differ