我正在創建一個程序,該程序接收整數值並使用atoi將它們轉換爲2的補碼整數,並確定進行了哪種類型的轉彎。這裏是我的代碼:錯誤:沒有鏈接的'y2'的重新聲明
#include <stdio.h>
#include <stdlib.h>
int turn(int turn, int a1, int b1, int a2, int b2, int a3, int b3){
;
turn = ((a1 * b1 + b1 * a3 + a2 * a3) - (b2 * a3 + a1 * b3 + a2 * b1));
printf("\n value = %d \n", turn);
return(turn);
}
int main(int argc, char *argv[]) {
int x1, y2, x2, y2, x3, y3, turn;
x1 = atoi(argv[1]);
y1 = atoi(argv[2]);
x2 = atoi(argv[3]);
y2 = atoi(argv[4]);
x3 = atoi(argv[5]);
y3 = atoi(argv[6]);
turn = turn(x1, y1, x2, y2, x3, y3);
if(turn == 0) printf("\n Straight \n");
if(turn < 0) printf("\n Right Turn \n");
if(turn > 0) printf("\n Left Turn \n");
return 0 ;
}
而且我的錯誤:
make -k p3
cc p3.c -o p3
p3.c: In function ‘main’:
p3.c:29:19: error: redeclaration of ‘y2’ with no linkage
p3.c:29:11: note: previous declaration of ‘y2’ was here
p3.c:32:3: error: ‘y1’ undeclared (first use in this function)
p3.c:32:3: note: each undeclared identifier is reported only once for each function it appears in
p3.c:38:14: error: called object ‘turn’ is not a function
make: *** [p3] Error 1
編譯的代碼2日太陽異常退出9月22日20時07分02" 秒
我想知道這種情況的原因錯誤。
感謝,
對於函數名和參數名都使用「turn」是最好的。使用這個參數作爲局部變量更不健康。你強迫調用者轉()來證明第一個參數不被用來傳遞或返回一個值,這樣你就不必在返回之前聲明一個局部變量來保存結果。我建議你從參數列表中「轉出」,然後聲明一個局部變量,最好使用不同的名稱。 –
轉彎功能編譯很奇怪。轉可能是一個函數指針,並導致分配給左值的問題。外轉也造成主 –