c-为计算翻译的程序返回一个结构



我会制作一个程序,通过平移向量计算点的平移。为了做到这一点,我想将我的结构返回到我的主:

#ifndef _STRUCT_H_
#define _STRUCT_H_
typedef struct s_result
{
  int   result1;
  int   result2;
}       t_result;
#endif /* _STRUCT_H_ */

但我有一个编译错误:

Translation.c:15:16: error: return type is an incomplete type
Translation.c: In function ‘my_translation’:
Translation.c:29:3: warning: ‘return’ with a value, in function returning void [enabled by default]
Translation.c: In function ‘main’:
Translation.c:45:12: error: void value not ignored as it ought to be

功能:

struct  s_trans my_translation(char *av1, char *av2, char *av3, char *av4)
{
  int   x;
  int   y;
  int   tx;
  int   ty;
  t_result      s_trans;
  x = atoi(av1);
  y = atoi(av2);
  tx = atoi(av3);
  ty = atoi(av4);
  s_trans.result1 = x + tx;
  s_trans.result2 = y + ty;
  return (s_trans);
}
int     main(int ac, char **av)
{
  int   i;
  int   j;
  int   trans_tab[2];
  t_result      s_trans;
  i = 0;
  j = 0;
  while (av[j])
    {
      if (av[j] == "T")
        {
          s_trans = my_translation(av[j - 2], av[j - 1], av[j + 1], av[j + 2]);
          printf("Translation de vecteur (%d, %d)", trans_tab[0], trans_tab[1]);
        }
      ++j;
    }
}

您将从my_translation返回struct s_trans而不是struct t_result。由于已经对结构体进行了typedef,因此在声明返回类型时可以省略struct,而只返回t_result

相关内容

最新更新