我想创建一个程序,它接收整数值并使用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异常退出编译“
我想知道这个错误的原因。
谢谢,
答案 0 :(得分:1)
您收到的错误正是消息告诉您的错误。
y2
两次y1
turn
变量,其名称与turn
函数相同。答案 1 :(得分:1)
在声明int()中的main()之前;你有这样的东西int Turn(){; 应该是{或;。
在Main()中,你声明Y2两次,其中一个应该是Y1。
注意:打开后{不可能;在你的代码中,它就在那里