-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc0f0d8
commit 4618aed
Showing
5 changed files
with
89 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<iostream.h> | ||
#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; i<HZ_NUM; i++) HZFreq[i]=0; | ||
FILE *in; | ||
unsigned char c1, c2; | ||
int id; | ||
in=fopen(FileName, "rb"); | ||
if(in==NULL) | ||
{ | ||
printf("无法打开输入文件!"); | ||
// 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); | ||
|
||
strcat(FileName,".hzf"); | ||
FILE *outFile; | ||
outFile=fopen(/*(const char *)*/FileName, "wt"); | ||
for(id=0; id<HZ_NUM; id++) | ||
if(HZFreq[id]>0) | ||
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<argc; i++) | ||
cout<<argv[i]<<endl; | ||
//cin>>i; | ||
if(argc==2) | ||
{ | ||
char *fileName=argv[1]; | ||
hzInFile(fileName); | ||
} | ||
cout<<"任务完成。"<<endl; | ||
return 0; | ||
} | ||
*/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
#include<stdio.h> | ||
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<stdio.h> | ||
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(); | ||
}*/ |
Binary file not shown.