我已经复制了下面的整个代码并对我收到错误的行进行了评论。
我正在尝试测试我在网上找到的iDFT算法,但我无法将其编译,当我尝试编译时,任何人都可以帮我解决以下错误消息吗?
错误:数组下标
的类型'float [100] [float]'无效
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
float static X[100],X_Real[100],X_Imag[100];
float k,n,N;
printf("\t\t\t Inverse Discrete Fourier Transform(IDFT)");
printf("\n\n Enter the length of DFT N=");
scanf("%f",&N);
printf("\n Enter the real and imaginary parts of X(k) as follows:\n\n"
"X(k) =Real{X(k)} Img{X(k)} \n" );
for(k=0;k<N;k++)
{
printf("X(%1.0f)=",k);
scanf("%f %f",&X_Real[k],&X_Imag[k]); // This is where I get the error
}
for(n=0;n<N;n++)
{
X[n]=0;
for(k=0;k<N;k++)
{
X[n]=X[n]+X_Real[k]*cos((2*M_PI*k*n)/N)-X_Imag[k]*sin((2*M_PI*k*n)/N);
}
X[n]=X[n]/N;
}
printf("\n\n The sequence x(n) is as follows...");
for(n=0;n<N;n++)
{
printf("\n\n X(%1.0f)=%3.6f",n,X[n]);
}
getch();
}
答案 0 :(得分:1)
The error is telling you exactly what's wrong: k, n,
and N
must be declared as integers. You can't access an array with a float index (what's the 2.34th value in this array)?