Skip to content

Commit

Permalink
cheers
Browse files Browse the repository at this point in the history
  • Loading branch information
loveisbelief committed Feb 8, 2017
1 parent fc0f0d8 commit 4618aed
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 61 deletions.
46 changes: 0 additions & 46 deletions hzInFile.cpp

This file was deleted.

69 changes: 69 additions & 0 deletions hzInFile/hzInFile.cpp
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 added hzInFile/hzInFile.exe
Binary file not shown.
35 changes: 20 additions & 15 deletions chlp.c → print_GB2312/chlp.c
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 added print_GB2312/print_GB2312.exe
Binary file not shown.

0 comments on commit 4618aed

Please sign in to comment.