Tag: 成员

c – 错误:在非结构或联合的情况下请求成员xxxxxx

这是一个旨在使用ppm图像文件的程序。 我在尝试使用接受全局结构变量并提取该图像成员的函数时遇到编译错误。 这是全局结构(在ppmIO.c和ppmIO.h中声明): ppmIO.c: struct Image *instance; ppmIO.h: struct Image { int width; int height; unsigned char *data; }; extern struct Image *instance; 这就是我从main调用我的函数的方法: ImageInvert(&instance); 这些是我的imageManip.c文件的相关部分: #include #include #include #include #include void ImageInvert(struct Image **toInvert) { int i; int pix = (*toInvert->width) * (*toInvert->height); for (i = 0; i data = ((unsigned char)255 – *(toInvert)->data)); […]

将结构成员NAME传递给C中的函数?

有没有简单的方法将结构成员的名称传递给C中的函数? 例如,如果我想要实现这一点: (我知道代码不正确,我只是写它来解释这个问题) struct Test { int x; int y; }; int main() { struct Test t; tx = 5; ty = 10; example(t, ); } void example(struct Test t, ) { printf(“%d”, t.); }

C中静态结构的成员变量

我有一个关于C语言中静态结构的成员变量的问题。 有人说我们可以声明一个static struct ,但是在C中,struct没有像C ++中的类那样的静态成员,这是什么意思? 如果我声明一个静态结构,那么成员变量的状态是什么? 有人可以帮我吗?