dnf更新游戏md5:里面程序是用什么原理实现的?

来源:百度文库 编辑:神马品牌网 时间:2024/05/07 04:01:36
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <sys\stat.h>
int chrcnt(const char *string,int letter);
long filel(const char *path);
int main(void)
{
FILE *stream;
char gets[20];
char ch='a';
int i=0;
int runCount=0;
char chFinded[200];
int chCount[200]={0};
int flag=0;
int totalCount=0;
long length;
char path[100]="d:\\a.txt";
fpos_t fpos;
length=filel(path);/*取出文件长度*/
/*printf("%d",length);*/
if ((stream=fopen(path,"r"))==NULL)
{
printf("Error");
getch();
exit(1);
}
fgetpos(stream,&fpos);
do
{
flag=0;
totalCount=0;
fsetpos(stream,&fpos);/*设置文件流中的指针*/
ch=getc(stream);/*从文件中取出字符*/
fgetpos(stream,&fpos);/*取出文件流中的指针*/
for (i=0;i<=runCount;i++)/*在已经查找的字符数组查找是否存在正在查找的字符,存在则break,最文件的下一个字符进行判断直到文件结束*/
{
/*printf("%c-----%c\n",chFinded[i],ch);*/
if((chFinded[i] == ch) || (ch == '\n'))
{
flag=1;
break;
}
}
/*printf("%c\n",ch);*/
if(flag == 0)/*判断当前字符是否已经计算*/
{
runCount++;
chFinded[runCount]=ch;/*往已经查找过的字符数组中添加正在查找的字符*/
i=0;
fsetpos(stream,0);
while ( i < length )
{
fgets(gets,21,stream);/*从文件中取出20个字符*/
i+=strlen(gets);
totalCount+=chrcnt(gets,ch);/*计算指定字符出现的次数*/
/*printf("%d---%d\n",chrcnt(gets,ch),totalCount);*/
/* printf("%s:%d\n",gets,strlen(gets)); */
/* printf("length:%d----i:%d\n",i,length); */
}
chCount[runCount]=totalCount;/*存储当前查找字符的人数*/
}

/*printf("%c---%d",chFinded[runCount],chCount[runCount]);*/
}
while ( ch != EOF );
for (i=0;i<100 ;i++ )/*输出已经统计过的字符,和相应的个数,,和所占的比率*/
{
if(chCount[i] != 0 )
{
printf("The char:'%c'--show %d times,rate%f\n",chFinded[i],chCount[i],chCount[i]/(float)length);
}
}
fclose(stream);
getch();
}
int chrcnt(const char *string,int letter) /*指定计算字符串内的指定字符的个数*/
{
int count=0;
int i=0;
char temp;
for (i=0;i<strlen(string);i++)
{
temp=string[i];
/*printf("%c--%c",letter,string[i]);*/
if(temp == letter)
count++;
}
return count;
}
long filel(const char *path)/*得到指定文件的长度*/
{
int handle;
long length;
handle = open(path,O_RDONLY);
length=filelength(handle);
close(handle);
return length;
}

该程序是用TC运行的,但是小弟编程不地道,各位大虾能解释下该程序是用什么原理实现的?还有能用多少方法能实现信源?高手请留言,越详细越好,谢谢大家。

什么原理?这是一个读取文件中的字符窜,再对字符串进行操作,用到一些函数。