i want to write a program which display alert message whenever 15 mins are over.But i am not finding solution of my problem using waitforexit() or delay() functions.

#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<conio.h>
void main(void)
{

time_t timer;
struct tm *tblock;
time_t t;
//timeout=18000;
	/* gets time of day */
	timer = time(NULL);
	/* converts date/time to a structure */
	tblock = localtime(&timer);
	t = time(NULL);
	printf("Local time is: %s", asctime(tblock));
	printf("The number of seconds since January 1, 1970 is %ld",t);


	while(1)
	{
		sleep(150);
		printf("\n\n\n\n**********************times up************************\n\n");
		getch();
	};


}

Recommended Answers

All 2 Replies

Do you want your program to do other things in the meantime? If you do, then put the alert messages in another thread, but your compiler may not support multi-threaded programs. So an alternative might be to use a loop

time_t t1, t2; // time variables
double dif;
t1 = time(0); // get current time
while(true)
{
   t2 = time(0);
   dif = diftime(t2,t1);
   if( dif >= (double)(15 * 60) ) // if 15 minutes expired
   {
      // display alert message
      //
      // reset timer
      t1 = t2;
   }
   // do other stuff here
}
#include<time.h>
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
int true=1,num;
char ch;

time_t t1, t2; // time variables
double dif;
t1 = time(0); // get current time
printf("\n__________________________counting time____________________");
while(true)
{  num=0;
	t2 = time(0);
	dif = difftime(t2,t1);
	if( dif >= (double)(1 * 60) ) // if 15 minutes expired
	{
																												// display alert message
		printf("\n--------------\a-------------times up!----------------------------");
		printf("\n----------------------------thanks!-----------------------------");
		getch();
																												// reset timer
		t1 = t2;
		clrscr();
		num=1;
	if(num==1)
		{
		printf("\nEnter * to close app:");      														 //condition to limit the loop
		ch=getche();
		if(ch=='*')
		exit(0);
		}
	}
}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.