我也不知道是哪里错了。。调试的时候也没报错,一运行就是error
#include <stdio.h>#include <math.h>
#include <stdlib.h>
int main()
{
void count_r(FILE *c,int num);
FILE *read;
int n;
read=fopen("data_v.txt","r");
fseek(read,0,SEEK_SET);
fseek(read,0,SEEK_END);
n=ftell(read);
rewind(read);
if (read==NULL)
{
printf("can't open this file\n ");
exit(0);
}
count_r(read,n);
fclose(read);
return 0;
}
void count_r(FILE *c,int num)
{
char x='a';
int i,y;
double ic,d;
char *f=(char *)malloc((num+1)*sizeof(char));
fread(f,1,num,c);
struct mem
{
char letter;
int number;
double p;
}member[26];
for (i=0;i<26;i++)
{
member[i].letter=x;
member[i].number=0;
member[i].p=0.0;
x++;
}
for(i=0;i<num;i++)
{
switch (f[i])
{
case 'a':member[0].number++;break;
case 'b':member[1].number++;break;
case 'c':member[2].number++;break;
case 'd':member[3].number++;break;
case 'e':member[4].number++;break;
case 'f':member[5].number++;break;
case 'g':member[6].number++;break;
case 'h':member[7].number++;break;
case 'i':member[8].number++;break;
case 'j':member[9].number++;break;
case 'k':member[10].number++;break;
case 'l':member[11].number++;break;
case 'm':member[12].number++;break;
case 'n':member[13].number++;break;
case 'o':member[14].number++;break;
case 'p':member[15].number++;break;
case 'q':member[16].number++;break;
case 'r':member[17].number++;break;
case 's':member[18].number++;break;
case 't':member[19].number++;break;
case 'u':member[20].number++;break;
case 'v':member[21].number++;break;
case 'w':member[22].number++;break;
case 'x':member[23].number++;break;
case 'y':member[24].number++;break;
case 'z':member[25].number++;break;
default:;break;
}
}
for (i=0;i<26;i++)
{
member[i].p=1.0*member[i].number/num;
y=y+member[i].number*(member[i].number-1);
}
ic=1.0*y/(num*(num-1));
d=0.027*num/((num-1)*ic-0.0385*num-0.0655);
free(f);
printf("%l",d);
}