📄 test1.cpp
字号:
// test1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <windows.h>
//#include "stdio.h"
#include <iomanip.h>
extern "C" struct __declspec(dllimport) STATIC{
unsigned short incode;
unsigned long int cishu;
};
extern "C" __declspec(dllimport) unsigned long count;
extern "C" __declspec(dllimport) long int high;
extern "C" __declspec(dllimport) STATIC out[6763];
extern "C" __declspec(dllimport) void fStaticdll(char *filename,int ff);
int main(int argc, char* argv[])
{
//start find files
char CurPath[MAX_PATH];
char filename[200][20];
int ff=0;
if(FALSE==GetCurrentDirectory(sizeof(CurPath)/sizeof(char),CurPath))
{
cerr<<"Error at get directory!"
<<endl;
return 0;
}
char *FindDir="D:\\yb";
HANDLE hFind=NULL;
WIN32_FIND_DATA wfdt;
if(FALSE==SetCurrentDirectory(FindDir))
{
cerr<<"Error at set current directory"
<<endl;
return 0;
}
hFind=FindFirstFile("*.*",&wfdt);
if(hFind==INVALID_HANDLE_VALUE)
{
cerr<<"Error at hFind handle!"
<<endl;
return 0;
}
if((wfdt.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0&&
(strcmp(wfdt.cFileName,".")!=0)&&
(strcmp(wfdt.cFileName,"..")!=0))
cout<<"\tFind a child directory!"<<endl;
else if(!strcmp(wfdt.cFileName,".")||!strcmp(wfdt.cFileName,".."))
cout<<"\t Find a current or parent directory @!:"
<<wfdt.cFileName
<<endl;
else
{
cout<<"find the first file@!"
<<'\t'<<wfdt.cFileName
<<endl;
strcpy(filename[ff],wfdt.cFileName);
ff++;
}
while(FindNextFile(hFind,&wfdt)!=FALSE)
{
if((wfdt.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0&&
(strcmp(wfdt.cFileName,".")!=0)&&
(strcmp(wfdt.cFileName,"..")!=0))
cout<<"\tFind a child directory!"
<<'\t'<<wfdt.cFileName
<<endl;
else if(!strcmp(wfdt.cFileName,"..")||!strcmp(wfdt.cFileName,"."))
cout<<"\t Find a current or parent directory @!:"
<<wfdt.cFileName
<<endl;
else
{
cout<<"find the our need file@!"
<<'\t'<<wfdt.cFileName
<<endl;
strcpy(filename[ff],wfdt.cFileName);
ff++;
}
}
// if(FindNextFile(hFind,&wfdt)==FALSE)
// cout<<GetLastError()
// <<"\terror!error@error#"
// <<endl;
FindClose(hFind);
//statics
char* fileaddr=*filename;
fStaticdll(fileaddr, ff);
//output file
SetCurrentDirectory(CurPath);
//output statics
ofstream outfile("d:\\yb\\out.txt");
if(!outfile)
{
cout<<"Can't open output file!"<<endl;
return 0;
}
outfile<<"\ttotal words:\t"
<<count<<'\t'
<<"category word:"
<<high<<endl
<<"\tword\t"
<<"incode\t"
<<"count\t"
<<"Frequency"<<endl;
int sort[6763];
for(int t=0;t<high;t++)
{
sort[t]=t;
}
int kk;int cj;
for(int c=0;c<high-1;c++)
{
kk=c;
for(int j=c+1;j<high;j++)
{
if(out[sort[kk]].cishu<out[sort[j]].cishu)
{
kk=j;
}
}
if(kk!=c)
{
cj=sort[c];
sort[c]=sort[kk];
sort[kk]=cj;
}
}
unsigned char ss[3];
for( c=0;c<high;c++)
{
ss[0]=(unsigned char)((out[sort[c]].incode&0xff00)>>8);
ss[1]=(unsigned char)(out[sort[c]].incode&0x00ff);
ss[2]='\0';
outfile<<'\t'
<<ss
<<setiosflags(ios::showbase)
<<'\t'<<hex<<out[sort[c]].incode
<<'\t'<<dec<<out[sort[c]].cishu
<<'\t'<<(float)(out[sort[c]].cishu)/(float)(count)
<<endl;
}
outfile.close();
char bb='\007';
cout<<bb;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -