无法在 C 中将结构指针作为函数参数传递

标签 c function pointers struct compiler-errors

我正在尝试编译一些代码,但我一直收到错误:

unknown type name ‘ label’;

我已经在 main 中声明了这些结构,我不确定为什么会得到这个。 我在 main 之前声明每个函数原型(prototype),然后在 main 之后声明函数原型(prototype)。

我想我记得这样做过,难道我不应该这样做吗?我不确定我将如何更早地声明这些结构。

我的代码:

void greyScale(Image* image);
void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
void strech(Image* image);
void findEffect(Image* image,char effect[20]);

int main(int argc, char **argv)
{
    char effect[20];

    /*file i/o stuff*/

    typedef struct Pixel{
      int red;
      int green;
      int blue;
    } Pixel;

    typedef struct Imagem{
      int width;
      int height;
      Pixel **pixel;
    } Image;

    Image *image;

    /*reads files, calls functions etc..*/

    return 0;
}

void greyScale(Image* image)
{
   /*code*/
}

void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);
{
   /*code*/
}    

void strech(Image* image);
{
   /*code*/
}   

void findEffect(Image* image,char effect[20]);
{
   /*code*/
}

最佳答案

查看此引用 C_structures

把你的 typedef 移到外面

typedef struct Pixel{
  int red;
  int green;
  int blue;
} Pixel;

typedef struct Imagem{
  int width;
  int height;
  Pixel **pixel;
} Image;

void greyScale(Image* image);

void findMaxMin(Pixel** colour,Pixel* max,Pixel* min);

void strech(Image* image);

void findEffect(Image* image,char effect[20]);

关于无法在 C 中将结构指针作为函数参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40942862/

相关文章:

更改 "Restrict"ed 指针的顺序会产生不同的程序集

c - 使用 mosquitto API 实现 mqtt 协议(protocol)

c - `realloc(): invalid next size` 尝试处理未知大小的输入

c - 16 位微 Controller 上的正弦函数

c++ - 如何删除属于指针对象的指针 vector 中的项目

C:使用指针打印出数组每个元素的值和内存位置?

c - 有没有办法将所有指向已释放内存的指针设置为 NULL?

python - 二分查找小错误Python 3.5

function - iif(Iserror())函数仍然返回#error

R-项目错误消息 - 无法读取表格