我正在尝试创建一个程序,该程序接收整数值并使用 atoi 将它们转换为 2 的补码整数,并确定进行了哪种类型的转弯。这是我的代码:
#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 在 Sun Sep 22 20:07:02"
我想知道这个错误的原因。
谢谢,