【问题标题】:Return a struct for a program which calculate the translation返回计算翻译的程序的结构
【发布时间】:2013-12-11 16:58:58
【问题描述】:

我会编写一个程序,通过平移向量计算点的平移。 为此,我想将我的结构返回到我的主目录:

#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;
    }
}

【问题讨论】:

    标签: c struct return translation


    【解决方案1】:

    您从my_translation 返回struct s_trans 而不是struct t_result。由于您已经 typedefed 结构体,您可以在声明返回类型时省略 struct 并简单地返回 t_result

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-11
      • 2012-12-14
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多