c-错误:请求成员xxxxxx的内容不是结构体或联合体 [英] c - error: request for member xxxxxx in something not a structure or union

查看:228
本文介绍了c-错误:请求成员xxxxxx的内容不是结构体或联合体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个用于处理ppm图像文件的程序.

This is in a program meant to work with ppm image files.

尝试使用接受全局struct变量并提取该图像成员的函数时,出现编译错误.

I'm getting a compilation error when trying to use a function that accepts a global struct variable and extracting that image's members.

这是全局结构(在ppmIO.c和ppmIO.h中声明):

This is the global struct (declared in ppmIO.c and ppmIO.h):

ppmIO.c:

struct Image *instance;

ppmIO.h:

struct Image
{
  int width;
  int height;
  unsigned char *data;
};

extern struct Image *instance;

这就是我从main调用函数的方式:

This is how I call my function from main:

  ImageInvert(&instance);

这些是我的imageManip.c文件的相关部分:

These are the relevant parts of my imageManip.c file:

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <ppmIO.h>
#include <imageManip.h>

void ImageInvert(struct Image **toInvert) {


  int i;
  int pix = (*toInvert->width) * (*toInvert->height);

  for (i = 0; i < pix; i++)
    {
      *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data));
      *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
      *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
    }

}

这是我的imageManip.h文件:

This is my imageManip.h file:

#include <ppmIO.h>

void ImageInvert(struct Image **toInvert);

void ImageSwap(struct Image **toSwap);

这些是我得到的错误:

imageManip.c:31:23: error: request for member ‘width’ in something not a structure or union
   int pix = (*toInvert->width) * (*toInvert->height);
                       ^
imageManip.c:31:44: error: request for member ‘height’ in something not a structure or union
   int pix = (*toInvert->width) * (*toInvert->height);
                                            ^
imageManip.c:35:18: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data));
                  ^
imageManip.c:35:60: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data));
                                                            ^
imageManip.c:35:67: error: expected ‘;’ before ‘)’ token
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data));
                                                                   ^
imageManip.c:35:67: error: expected statement before ‘)’ token
imageManip.c:36:18: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
                  ^
imageManip.c:36:60: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
                                                            ^
imageManip.c:36:69: error: expected ‘;’ before ‘)’ token
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
                                                                     ^
imageManip.c:36:69: error: expected statement before ‘)’ token
imageManip.c:37:18: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
                  ^
imageManip.c:37:60: error: request for member ‘data’ in something not a structure or union
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));
                                                            ^
imageManip.c:37:69: error: expected ‘;’ before ‘)’ token
       *(toInvert)->data = ((unsigned char)255 - *(toInvert)->data++));

不确定我是在正确访问成员还是在正确使用指针...

Not sure if I'm accessing the members correctly or if I'm making the right use of pointers...

推荐答案

我使用方括号的方式存在问题.

There was an issue with how I was using brackets.

这是imageInvert函数的有效版本:

This is a working version of the imageInvert function:

void ImageInvert(struct Image **toInvert) {


  int i;
  int pix = (*toInvert)->width * (*toInvert)->height;

  for (i = 0; i < pix; i++)
    {
      (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data);
      (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data++);
      (*toInvert)->data = ((unsigned char)255 - (unsigned char)(*toInvert)->data++);
    }

}

这篇关于c-错误:请求成员xxxxxx的内容不是结构体或联合体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆