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

标签 c struct return translation

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

#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。

关于c - 返回计算翻译的程序的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20525270/

相关文章:

c++ - 不同数据类型的二进制格式

python - 在Python中打包和解包浮点值

c - 程序不想读取文件

c - 我的回调结构不起作用

c++ - 返回地址是否确保非 NULL 返回值?

java - 如何使用 float 图标将所有复选框值返回到字符串

使用三元运算符获取所选变量的地址时出现编译错误

c - 指针声明中的错误数据类型

javascript - 如何从函数返回数据

c - 在lapack的dgels函数中使用malloc