c - 错误 "invalid use of undefined type ' struct cmplx'取消引用指向不完整类型的指针”。如何修复它?

标签 c pointers

我是 C 编程新手,我有一个别人编写的代码,我只需要使其工作或编译它。

 # include <stdio.h>
 # include <math.h>

 # define AP_INC        1
 # define H_INC     4

/* plot the power spectrum */
do_peak(ftdat,n_out,recno)
struct cmplx *ftdat;
int n_out;
int recno;
{
extern float del_f;
extern float del_t;
extern FILE *pkfile;
extern int ilowpk;
extern int ihipk;
float time;
float fpeak;
float pkval;
int ipeak;
int i;

/* find the peak of the spectrum */
pkval = ftdat[ilowpk];
ipeak = ilowpk;

if(ilowpk < ihipk){
    for(i = ilowpk+1; i < ihipk; i++){
        if(ftdat[i] > pkval){
            pkval = ftdat[i];
            ipeak = i;
        }
    }
} else {
    for(i = ilowpk+1; i < n_out; i++){
        if(ftdat[i] > pkval){
            pkval = ftdat[i];
            ipeak = i;
        }
    }
    for(i = 0; i < ihipk; i++){
        if(ftdat[i] > pkval){
            pkval = ftdat[i];
            ipeak = i;
        }
    }
}

/* convert ipeak to a frequency */
fpeak = (float)ipeak*del_f;

/* compute the time */
time = (float) recno*del_t;

/* write to output file */
fprintf(pkfile,"%f %g\n",time,fpeak);
return;
}

我得到的错误是“无效使用未定义类型'struct cmplx'取消引用指向不完整类型的指针” 大家可以查看此链接了解更多信息http://codepad.org/HdbgppgM 请让我知道如何解决它。 请记住,我对 C 语言一无所知,只知道 matlab。 谢谢 阿尼尔。

最佳答案

pkval = ftdat[ilowpk]; <- 在这里,您将 ftdat 视为指向 struct cmplx 数组的指针(类似于 char * 通常是一个字符数组),在位置提取一个 struct cmplx ilowpk 并将其分配给 pkval。

您无法从数组中提取结构,因为编译器拥有的只是一个前向声明 - 它不知道该结构有多大。因此,它甚至不知道在哪里查找与数组开头相关的位置。

关于c - 错误 "invalid use of undefined type ' struct cmplx'取消引用指向不完整类型的指针”。如何修复它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26286754/

相关文章:

c - 如何在 C 中反转单链表?

c++ - 我的 mandelbrot 集输出有线图像

C 函数使用带有字符串的 strcat

c++ - 如何转换指针以调用派生类函数/方法? C++

无法将地址传递给指针

c - 一月提醒程序中的strcmp()函数理解

c - 在给定值之后反转链表,而不创建新节点

c - 在 C 中分配指针时的显式转换

c - 将指向结构的指针设置为等于函数返回的另一个指向结构的指针?

c - 高效的手动循环展开