0
我真的不明白为什么我得到这个错误。从类型'int'分配类型't_result'时的不兼容类型,为什么?
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
(我没有忘记我的包含)。
“my_rota”不听起来很像“my_rotation”。保持您的代码清洁。 –
“cos”和“sin”有什么问题?我们可以猜测问题是什么吗? –
编译时没有启用足够的警告,因此您不知道编译器何时需要猜测函数的返回类型。你应该从'-Wall'开始;我使用'gcc -O3 -g -std = c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Werror',我希望我的代码能够编译。没有这样的警告可能会导致“cos”和“sin”的问题(换句话说,由于没有启用警告,您处于“罪恶”状态)。 –