2013-12-14 133 views
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_ */ 

另外,我有一些问题与cossin(我没有忘记我的包含)。

+2

“my_rota”不听起来很像“my_rotation”。保持您的代码清洁。 –

+0

“cos”和“sin”有什么问题?我们可以猜测问题是什么吗? –

+0

编译时没有启用足够的警告,因此您不知道编译器何时需要猜测函数的返回类型。你应该从'-Wall'开始;我使用'gcc -O3 -g -std = c11 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -Werror',我希望我的代码能够编译。没有这样的警告可能会导致“cos”和“sin”的问题(换句话说,由于没有启用警告,您处于“罪恶”状态)。 –

回答

1

编辑: @Hans指向了基本的问题,那你定义my_rotation试图调用my_rota。你应该先解决这个问题。


似乎是由implicit function declarations造成的。您是否在95行之前声明了功能my_rotation

你可以尝试加入这一行到你的头:

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

也要确保'#include '在使用'cos'和'sin'之前。 –

相关问题