Code:
/* Created by Dennis C. Development period's from 19 October 2002 to 21 October 2002. This program'll ends the running of Winamp program. */
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
void dispInvalidOptMess();
void dispMenu();
void endWinamp();
int getCountDown();
int getOption();
int
main()
{
do {
dispMenu();
} while (getOption() != '1');
return 0;
}
void
dispInvalidOptMess()
{
printf("\a\a\nInvalid Option Entered!\n");
system("pause");
}
void
dispMenu()
{
system("cls");
puts("SleepAmp (v 0.0)");
puts("\n[0] Input countdown time");
puts("[1] Return");
printf("\nOption: ");
}
void
endWinamp()
{
system("taskkill /im winamp.exe /t");
}
int
getCountDown()
{
time_t start_tm, hour, minute, second, second1;
time_t current_tm, diff_tm;
struct tm *time_tm;
fflush(stdin); /* fluch stdin in order to've proper subsequent input. */
printf("\n\nRemaining time to sleep the Winamp (hh:mm:ss): ");
/* check for correctness of time. */
if ((scanf("%d:%d:%d", &hour, &minute, &second) < 3) || (minute > 60) || (second > 60)) {
puts("\a\aInvalid Input!");
system("pause");
return 0;
}
second1 = (second + (minute * 60) + (hour * 60 * 60));
time(&start_tm);
while ((diff_tm = (time(¤t_tm) - start_tm)) < second1) {
/* if <Esc> key was pressed, return to calling function. */
if (kbhit())
switch (getch()) {
case 27:
return 0;
case 0: case 224:
getch();
}
/* get remaining time. */
diff_tm = (second1 - diff_tm);
time_tm = gmtime(&diff_tm);
printf("\r%d:%d:%d remaining...", time_tm->tm_hour, time_tm->tm_min, time_tm->tm_sec);
}
endWinamp();
return 1;
}
int
getOption()
{
switch (putch(getch())) {
default:
dispInvalidOptMess();
return 0;
case 0: case 224: /* function or extended keys? */
getch();
dispInvalidOptMess();
return 0;
case '0':
return getCountDown();
case '1':
return '1';
}
}