Hi there, I am very new to C programming and I have been trying to write a program for running traffic lights, with an interrupt key press for a pedestrian crossing of 30 secs then return back to the free running process. I am going mad trying to work out where I am going wrong.. Would anyone be able to help me out at all? here's the code I've written so far...
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
/*Timer set with integar of inputtime to be included after each phase of the traffic light operation*/
timer(int inputtime)
{
int buttonpressed = 0;
time_t start;
time_t current;
time(&start);
do
{
time(¤t);
/*Interupt operation in timer*/
//if enterkeypressed
{
int getchar();
if (getchar()) goto interupt;{
interupt:
printf("SAFE TO CROSS\n");
buttonpressed=timer(30.0);
system("cls");
exit(0);}
}
while(difftime(current,start) < inputtime);
return buttonpressed;
}
/*free running operation*/
freerunninglights()
{
int buttonpressed = 0;
printf("Road A - RED; Road B - GREEN\n");
buttonpressed=timer(6.0);
system("cls");
printf("Road A - RED/AMBER; Road B - AMBER\n");
buttonpressed=timer(5.0);
system("cls");
printf("Road A - GREEN; Road B - RED\n");
buttonpressed=timer(6.0);
system("cls");
printf("Road A - AMBER; Road B - RED/AMBER\n");
buttonpressed=timer(5.0);
system("cls");
}
/*main*/
int main()
{
while(1)
freerunninglights();
return 0;
}