Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 分配给类型'时不兼容的类型;t#u结果';从类型';int';,为什么?_C_Struct_Math.h - Fatal编程技术网

C 分配给类型'时不兼容的类型;t#u结果';从类型';int';,为什么?

C 分配给类型'时不兼容的类型;t#u结果';从类型';int';,为什么?,c,struct,math.h,C,Struct,Math.h,我真的不明白我为什么会犯这个错误 architect.c: In function ‘main’: architect.c:91:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’ architect.c:93:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’ architect.

我真的不明白我为什么会犯这个错误

architect.c: In function ‘main’:
architect.c:91:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’
architect.c:93:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’
architect.c:95:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’
architect.c:97:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’
architect.c:99:20: error: incompatible types when assigning to type ‘t_result’ from type ‘int’
这是我的代码:

    if (av[j][i] == 'R')
    {
        printf("rotation d'angle %s degrés\n", av[j + 1]);
        if (av[j - 3][i] == 'T')
91          s_rota = my_rota(s_trans.result1, s_trans.result2, atoi(av[j + 1]));
        else if (av[j - 3][i] == 'H')
93          s_rota = my_rota(s_homot.result1, s_homot.result2, atoi(av[j + 1]));
        else if (av[j - 2][i] == 'S')
95          s_rota = my_rota(s_sym.result1, s_sym.result2, atoi(av[j + 1]));
        else if (av[j - 2][i] == 'R')
97          s_rota = my_rota(s_rota.result1, s_rota.result2, atoi(av[j + 1]));
        else
99          s_rota = my_rota(atoi(av[j - 2]), atoi(av[j - 1]), atoi(av [j + 1]));
        printf("(%s,%s) => (%d,%d)\n", av[j - 2], av[j - 1], s_rota.result1, s_rota.result2);
    }
这是我的第二个功能:

t_result my_rotation(int x, int y, int degree)
{
    t_result s_rota;

    s_rota.result1 = (cos(degree) * x) - (sin(degree) * y);
    s_rota.result2 = (sin(degree) * x) + (cos(degree) * y);
    return (s_rota);
}
这是我的标题:

#ifndef _STRUCT_H_
#define _STRUCT_H_

typedef struct s_result
{
    int   result1;
    int   result2;
}   t_result;

#endif /*  _STRUCT_H_ */

另外,我对
cos
sin
有一些问题(我没有忘记我的include)。

编辑:@Hans指出了一个基本问题,即您在试图调用
我的旋转时定义了
我的旋转。你应该先把这个修好


似乎是由……引起的。您是否在第95行之前声明了函数
my_rotation

您可以尝试将此行添加到标题:

extern t_result my_rotation(int x, int y, int degree);

“我的旋转”听起来不像“我的旋转”。保持代码整洁。您在
cos
sin
方面有“一些问题”?我们猜猜问题出在哪里?您在编译时没有启用足够的警告,因此您不知道编译器何时必须猜测函数的返回类型。你应该从
-Wall
开始;我使用
gcc-O3-g-std=c11-Wall-Wextra-Wmissing原型-Wstrict原型-Wold样式定义-Werror
,我希望我的代码能够编译。缺少此类警告可能是导致
cos
sin
问题的原因(或者,换句话说,您生活在
sin
的状态中,因为您没有启用警告)。请注意
cos()
sin()
预期的参数是弧度,而不是度。您需要将输入除以
pi/180
(其中pi不是您将要使用的名称;例如,您可能可以使用M#pi)。此外,还要确保
#include
在使用
cos
sin
之前。