I am tring to create a program that recieves integer values and converts them into 2's complement integers using atoi, and determines what type of turn was made. Here is my code:
#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 ;
}
And my errors:
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
Compilation exited abnormally with code 2 at Sun Sep 22 20:07:02"
I am wondering the cause of this error.
Thanks,
The errors that you are getting are exactly what the message is telling you.
y2
twicey1
anywhere turn
variable which has the same name as your turn
function.