#include<stdio.h>
#include<stdlib.h>
# include<ctype.h>
#define N 43
int main( )
{
FILE *fp1,*fp2;
long i,count,sum=0;
char ch,m;
int num[N];
float prob[N];
char string[N]={'a','b','c','d','e','f','g','h','i',
'j','k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z',' ', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0','<','>',',','.''@','#'};
if((fp1=fopen("d:\\string.txt","w"))==NULL)
{
printf("cannot open this file.\n");
exit(0);
}
fwrite(string,sizeof(char),N,fp1);
if((fp2=fopen("d:\\wenjian.txt","r"))==NULL)
{
printf("cannot open this file.\n");
exit(0);
}
for(i=0;i<N;i++)
{
count=0;
ch=string[i];
while((m=fgetc(fp2))!=EOF)
{
if(isascii(m))
{
if(m==ch)
count++;
}
}
num[i]=count;
}
for(i=0;i<N;i++)
sum+=num[i];
for(i=0;i<N;i++)
prob[i]=num[i]/sum/1.00f;
fclose(fp1);
fp1=fopen("d:\\prob.txt","a+");
fwrite(prob,sizeof(char),N,fp1);
}