C Program to create a calendar for DOS

 


#include
#include
#include "scaldate.h"

/*
** calendar generation information
*/

int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char *month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char *daynames[8] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

/*
** box drawing stuff
*/

#if defined(MSDOS) || defined(_WIN32)
const char *topborder = "\xd5\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xb8";
const char *midborder = "\xc6\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xb5";
const char *botborder = "\xd4\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd"
"\xcd\xcd\xcd\xcd\xbe";
const char *line = "\xb3";
#else
const char *line = "";
#endif

/*
** tell 'em they messed up
*/

void usage(void)
{
puts("Usage: CAL [m y]");
puts("where: m = month (1 - 12)");
puts(" y = year (1 - 99, 1800 - 3000)");
exit(-1);
}

/*
** here's where the real work's done
*/

int main(int argc, char *argv[])
{
int day, day_1, numdays, i, j;
unsigned yr, mo;

if (argc < 3 && argc > 1)
usage();

if (argc >= 3)
{
yr = atoi(argv[2]);
mo = atoi(argv[1]);
}
else
{
long dnow = today();
unsigned dy;

scalar_to_ymd(dnow, &yr, &mo, &dy);
}

if (!mo || 12 < mo)
usage();

if (100 > yr)
yr += 1900;

if (3000 < yr || 1800 > yr)
usage();

for (i = 0, mo -= 1; i < 3; ++i, ++mo)
{
if (!mo)
{
mo = 12;
--yr;
}
if (12 < mo)
{
mo = 1;
++yr;
}
numdays = days[mo - 1];
if (2 == mo && isleap(yr))
++numdays;
day_1 = (int)((ymd_to_scalar(yr, mo, 1) - (long)ISO_CAL) % 7L);

#if defined(MSDOS) || defined(_WIN32)
if (!i)
puts(topborder);
#endif
fputs(line, stdout);
for (j = 0; j < 7; )
{
fputs(daynames[ISO_CAL + j], stdout);
if (7 != ++j)
fputc(' ', stdout);
}
printf("%s < %s, %d\n%s", line, month[mo - 1], yr, line);

for (day = 0; day < day_1; ++day)
fputs(" ", stdout);
for (day = 1; day <= numdays; ++day, ++day_1, day_1 %= 7)
{
if (!day_1 && 1 != day)
printf("\b%s\n%s", line, line);
printf("%3d ", day);
}
for ( ; day_1; ++day_1, day_1 %= 7)
fputs(" ", stdout);
#if defined(MSDOS) || defined(_WIN32)
printf("\b%s\n", line);
if (2 > i)
puts(midborder);
else puts(botborder);
#else
fputc('\n', stdout);
#endif
}
return 0;
}



Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!