思考不出 求助 c 问题
#include<stdio.h>#include<stdlib.h>
#include<math.h>
/*float h[52],dt,x[100],y[100];
FILE *fp,*fp1,*fp2;
float f1=70,f2=10,f=(f1+f2)/2,df=(f1-f2)/2,si=0.002;
int kc12,nech;
float sum;
int i,j,r;*/
void main( )
{
float h[52],dt,x[100],y[100];
FILE *fp,*fp1,*fp2;
float f1=70,f2=10,f=(f1+f2)/2,df=(f1-f2)/2,si=0.002;
int kc12,nech;
float sum;
int i,j,r;
//printf("%f",f);
fp=fopen("l4", "wb");
for(i=0; i<52; i++)
h[i]=0;
h[26]=4.0*f;
for(i=1; i<=25; i++)
{
dt=i*si;
h[26+i]=(2*cos(2.0*3.1416*f*dt)*
sin(2.0*3.1416*(df)*dt))/(3.1416*dt);
h[26-i]=h[26+i];
}
for(i=1; i<52; i++)
fprintf(fp, "%f\n", h[i]);
fclose(fp);
//====================================//
fp1=fopen("20-100", "rb");
fp2=fopen("PP", "wb");
printf("h-ok");
for(i=0; i<20; i++)
{
fread(&x[1],4,100,fp1);
for(j=0;j<100;j++)
y[j]=0;
for(r=0;r<=50;r++)
{
sum=0;
for(j=0;j<=50;j++)
{sum=sum+x[r+50-j]*h[j];
y[r+25]=sum;}
}
//printf("trace number %d\n", i);
fwrite(&y[1],4,100,fp2);
}
fclose(fp1);
fclose(fp2);
// return(0);
}
全局变量就可以得到结果,定义局部变量就没有结果,为什么呢