1,105,320 Community Members

how to measure half hour time in C language in terbo C++ 4.5 compiler?

Member Avatar
ravinder yadav
Light Poster
35 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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();
	};


}
Member Avatar
Ancient Dragon
Achieved Level 70
27,632 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

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
}
Member Avatar
ravinder yadav
Light Poster
35 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 
#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);
		}
	}
}

}
Question Answered as of 2 Years Ago by Ancient Dragon
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: