can anyone help with this error cant find it
Code:
#include <stdio.h>
#include <stdlib.h>
enum steerval {INVALID_SWITCH,
L_SL_RCVD,
R_SR_RCVD,
L_SR_RCVD,
R_SL_RCVD};
enum stateval {INVALID_STATE,
OFF,
L_WINK,
R_WINK,
LEFT_TURN,
RIGHT_TURN};
enum eventval {INVALID_EVENT,
TURN_LEFT,
TURN_RIGHT,
TURN_CANCEL,
SL_CLICKED,
SR_CLICKED};
enum indval {INVALID_SIG,
IND_OFF,
L_ON,
R_ON};
struct car
{
enum stateval state;
enum indval indicator;
enum steerval sr_sl;
enum eventval event;
};
void OnEventLeftIndON (struct car *myCar)
{
if (myCar->state == OFF)
{
myCar->state = L_WINK;
myCar->indicator = L_ON;
myCar->event = TURN_LEFT;
printf("\n Left Indicator is Turned ON\n");
}
else if (myCar->indicator == L_ON)
{
printf("\n Left Indicator is already ON\n");
}
else if (myCar->indicator == R_ON)
{
printf("\n Right Indicator is already ON.Can't Turn ON Left Indicator\n");
}
else if (myCar->state == LEFT_TURN)
{
/* Turn ON Left Indicator in half turn */
myCar->indicator = L_ON;
printf("\n Left Indicator is Turned ON\n");
}
else
{
/* Not a valid Request */
printf("\n Invalid Request\n");
}
return;
};
/* Event Handler for Right indicator ON */
void OnEventRightIndON (struct car *myCar)
{
if (myCar->state == OFF)
{
/* Turn ON Right indicator and change state */
myCar->state = R_WINK;
myCar->indicator = R_ON;
myCar->event = TURN_RIGHT;
printf("\n Right Indicator is Turned ON\n");
}
else if (myCar->indicator == R_ON)
{
/* Right indicator is already ON */
printf("\n Right Indicator is already ON\n");
}
else if (myCar->indicator == L_ON)
{
/* Left indicator is already ON */
printf("\n Left Indicator is already ON.Can't Turn ON Right Indicator\n");
}
else if (myCar->state == RIGHT_TURN)
{
/* Turn ON Right Indicator in half turn */
myCar->indicator = R_ON;
printf("\n Right Indicator is Turned ON\n");
}
else
{
/* Not a valid request */
printf("\n Invalid Request\n");
}
return;
};
/* Event Handler for indicator OFF */
void OnEventCancelInd (struct car *myCar)
{
if (myCar->indicator == IND_OFF)
{
printf("\n Indicator already turned OFF\n");
return;
}
if ((myCar->state == L_WINK) || (myCar->state == R_WINK))
{
myCar->indicator = IND_OFF;
myCar->state = OFF;
printf("\n Indicators Turned OFF\n");
return;
}
/* Turn OFF the indicator */
myCar->indicator = IND_OFF;
printf("\n Indicators Turned OFF\n");
return;
};
/* Event Handler for SL_CLICKED(Left Turn of steering wheel) */
void OnEventSLClicked (struct car *myCar)
{
switch (myCar->state)
{
case OFF:
case L_WINK:
/* Left Turn when Left Indicator is ON/OFF */
myCar->state = LEFT_TURN;
myCar->sr_sl = L_SL_RCVD;
printf("\n Taking a Left Turn\n");
break;
case LEFT_TURN:
/* No change as it is a small swerve */
printf("\n Taking a small left swerve\n");
break;
case RIGHT_TURN:
/* Turn Complete. Make the steering steady and auto turn-OFF indicator */
myCar->state = OFF;
myCar->indicator = IND_OFF;
printf("\n Turn Complete. Steering Steady. Indicator OFF\n");
break;
default:
/* Not a valid request */
printf("\n Invalid Request\n");
break;
}
};
/* Event Handler for SR_CLICKED(Right Turn of steering wheel) */
void OnEventSRClicked (struct car *myCar)
{
switch (myCar->state)
{
case OFF:
case R_WINK:
/* Right Turn when Right Indicator is ON/OFF */
myCar->state = RIGHT_TURN;
myCar->sr_sl = R_SR_RCVD;
printf("\n Taking a Right Turn\n");
break;
case RIGHT_TURN:
/* No change as it is a small swerve */
printf("\n Taking a small right swerve\n");
break;
case LEFT_TURN:
/* Turn Complete. Make the steering steady and auto turn-OFF indicator */
myCar->state = OFF;
myCar->indicator = IND_OFF;
printf("\n Turn Complete. Steering Steady. Indicator OFF\n");
break;
default:
/* Not a valid request */
printf("\n Invalid Request\n");
break;
}
};
int initializeSystem (struct car *myCar)
{
myCar->state = OFF;
myCar->indicator = IND_OFF;
myCar->sr_sl = INVALID_SWITCH;
myCar->event = INVALID_EVENT;
return 0;
};
int usageDisplay (void)
{
printf("\n Press \'C\' to Turn-OFF indicators\n");
printf("\n Press \'l\' to Turn-ON Left indicator\n");
printf("\n Press \'r\' to Turn-ON Right indicator\n");
printf("\n Press \'L\' to Turn Left\n");
printf("\n Press \'R\' to Turn Right\n");
printf("\n Press \'X\' to Quit\n");
return 0;
};
int main (void)
{
struct car *myCar;
char choice;
int dummy;
/* Memory alloc for myCar */
myCar = (struct car *)malloc (sizeof(struct car));
if (myCar == NULL)
{
/* malloc failed. Return failure */
printf("\n Invalid memory\n");
return -1;
}
/* Initialize Car Control System */
int initializeSystem (myCar);
while(1)
{
/* Display help context */
int usageDisplay (void);
/* Receive inputs from user through keyboard */
choice = getchar();
dummy = getchar();
/* Validate and act upon user input */
switch(choice)
{
case 'l':
OnEventLeftIndON(myCar);
break;
case 'r':
OnEventRightIndON(myCar);
break;
case 'L':
OnEventSLClicked(myCar);
break;
case 'R':
OnEventSRClicked(myCar);
break;
case 'X':
free(myCar);
return 0;
case 'C':
OnEventCancelInd(myCar);
break;
default:
printf("\n\n Error\n");
}
printf("\n\t\t\t\tCURRENT STATE\n");
switch(myCar->state)
{
case OFF:
printf("\nSteering wheel steady. Indicator OFF\n");
break;
case L_WINK:
printf("\nSteering wheel steady. Left Indicator ON\n");
break;
case R_WINK:
printf("\nSteering wheel steady. Right Indicator ON\n");
break;
case LEFT_TURN:
printf("\nTaking Left Turn\n");
break;
case RIGHT_TURN:
printf("\nTaking Right Turn\n");
break;
}
printf("\n\n");
}
free(myCar);
return 0;
}
--warning C4013: 'initializeSystem' undefined; assuming extern returning int
---d:\my documents2\uwe\csa\ind_new\indicator\ind.c(175) : warning C4013: 'usageDisplay' undefined; assuming extern returning int
---d:\my documents2\uwe\csa\ind_new\indicator\ind.c(234) : error C2371: 'initializeSystem' : redefinition; different basic types
---d:\my documents2\uwe\csa\ind_new\indicator\ind.c(243) : error C2371: 'usageDisplay' : redefinition; different basic types
Error executing cl.exe.]
ind.obj - 2 error(s), 2 warning(s)