2013-12-14 135 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'之前。 –

相關問題