h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <dos.h>
//Global Vars
int c, h, w, i;
struct text_info t_info;
int main()
{
struct tm full_m;
time_t fm_dbase,now;
register double span;
double phase_secs = 2551442.8;
double half_phase = phase_secs /2L;
double days_slfm,days_tnfm,days_tnnm,days_slnm;
double secs_slfm, secs_tnfm, value;
long whole_num;
int phase;
Init();
start:
clrscr();
full_m.tm_sec = 0;
full_m.tm_min = 16; /*24*/
full_m.tm_hour = 2; /*2*/
full_m.tm_mday = 7; /*04*/ /*day of month!*/
full_m.tm_mon = 0; /*5*/ /* 0=JAN */
full_m.tm_year = 85; /*93*/
fm_dbase = mktime(&full_m); /*mktime() Convt tm struct to time_t value.*/
now = time(NULL);
span = difftime(now, fm_dbase);
value = span / phase_secs;
whole_num = value; /* trick! Assign float value to integer. (kill ext)*/
value = whole_num * phase_secs; /* value = all full phases past in secs*/
secs_slfm = span - value;
secs_tnfm = phase_secs - secs_slfm;
days_slfm = secs_slfm /(60L*60L*24L);
days_tnfm = secs_tnfm /(60L*60L*24L);
if(secs_tnfm < half_phase)
days_tnnm = (secs_tnfm + half_phase) /(60L*60L*24L);
else{
days_tnnm = (secs_tnfm - half_phase) /(60L*60L*24L);
}
if(secs_slfm < half_phase)
days_slnm = (secs_slfm + half_phase)/(60L*60L*24L);
else{
days_slnm = (secs_slfm - half_phase)/(60L*60L*24L);
}
textattr(BLUE *16|WHITE);
gotoxy(6, 6);
cprintf("%.1f days until next new moon",days_tnnm);
gotoxy(6, 8);
cprintf("%.1f days until next full moon",days_tnfm);
gotoxy(6, 7);
cprintf("%.1f days since last new moon",days_slnm);
gotoxy(6, 9);
cprintf("%.1f days since last full moon",days_slfm);
while (!kbhit())
{
time(&timer); // Store elapsed seconds in timer.
timeptr = localtime(&timer); // localtime / gmtime
sec = timeptr->tm_sec;
if(sec == 0) {
delay(999);
goto start;
}
}
if ( getch() < 257 )
break;
}
clrscr();
_setcursortype(_NORMALCURSOR);
return(0);
}
register int i;
gotoxy(2, 2);
for(i=1; i <= end_horiz - start_horiz-2; i++)
putch(178);
/* bottom line */
gotoxy(2, end_vert - start_vert-1);
for(i=1; i <= end_horiz - start_horiz-2; i++)
putch(178);
for(i=2; i <= end_vert - start_vert-1; i++)
{
gotoxy(2, i);
putch(178);
gotoxy(end_horiz - start_horiz - 1, i);
putch(178);
}
}
gotoxy(4, 3);
for(i=1; i <= end_horiz - start_horiz - 5; i++)
putch(176);
/* bottom line */
gotoxy(2, end_vert-start_vert);
for(i=2; i <= end_horiz - start_horiz; i++)
putch(176);
/* bottom line */
gotoxy(1, 1);
putch(201);
void Init(void)
{
_setcursortype(_NOCURSOR);
clrscr();
gettextinfo(&t_info);
w = t_info.screenwidth;
h = t_info.screenheight;
}