我已复制下面的整个代码并在我收到错误的行上发表了评论。
我正在尝试测试我在网上找到的 iDFT 算法,但无法编译它,当我尝试编译时,任何人都可以帮助我解决以下错误消息吗?
error: invalid types 'float [100][float]' for array subscript
#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();
}
最佳答案
该错误准确地告诉您出了什么问题:k、n、
和 N
必须声明为整数。您无法访问具有浮点索引的数组(该数组中的第 2.34 个值是多少)?
关于c - 错误 "invalid types ' 浮点 [100][浮点 ]' for array subscript",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43260860/