Bdays.c
Bday.c
Bdays.c
/* * * * * * * * * * * * * * * * * * * * * * * *
* * Author:
* * Rajesh _ThE gReAt
* * License:
* * This program is freely
* My ][ nd program using data structures ! * distributable under GNU
* * public license .I hope u
* * keep my name while
* * distributing this program
* -By Rajesh _ThE gReAt * bye
* * Rajesh _ThE gReAt
* * * * * * * * * * * * * * * * * * * * * * * */
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<rajesh.h>
union bday
{
struct birthday
{
char name[30];
int day;
int month;
} date;
char bytes[sizeof(struct birthday)];
};
struct dosdate_t real_date;
main(int no_of_args,char *args[])
{
if(no_of_args == 1) /* No arguments input */
{
print_help();
}
else if(!strcmpi(args[1],"ip"))
input_mode();
else if(!strcmpi(args[1],"op"))
output_mode();
else if(!strcmpi(args[1],"flush"))
flush_file();
}
input_mode()
{
union bday a;
int i;
char ans[3];
char buffer;
FILE *fopen(),
*fp;
do
{
clrscr();
printf("\nEnter subject\'s name:");
fflush(stdin);
for(i = 0;(buffer = getchar()) != '\n';i++)
a.date.name[i]=buffer;
a.date.name[i] = '\0';
do
{
printf("\nEnter the day of subject\'s birth:");
scanf("%d",&a.date.day);
}
while(a.date.day > 31 || a.date.day < 1);
do
{
printf("\nEnter the month of subject\'s birth (jan = 1 etc.):");
scanf("%d",&a.date.month);
}
while(a.date.month > 12 || a.date.month < 1);
fp = fopen("bdays.dat","a+");
for(i=0;i<sizeof(a);i++)
putc(a.bytes[i],fp);
fclose(fp);
do
{
printf("\nDo you want to enter another subject ? (y/n/o)\n\t[y]=yes\t[n]=no\t[o]=go to output mode\nYor option:");
scanf("%s",ans);
if(*ans != 'o' && *ans != 'O' && *ans != 'y' && *ans != 'Y' && *ans != 'n' && *ans != 'N')
printf("\nInvalid switch %c",*ans);
}
while(*ans != 'o' && *ans != 'O' && *ans != 'y' && *ans != 'Y' && *ans != 'n' && *ans != 'N');
}
while(*ans=='y' || *ans == 'Y');
if(*ans == 'o' || *ans == 'O')
output_mode();
}
print_help()
{
char buffer[10];
printf("\nBirthday remebering utility by Rajesh\n\n");
printf("\nSyntax\n");
printf("\nBdays [ip] : For inputting birthdays");
printf("\nBdays [op] : For getting data stored");
printf("\nBdays [flush] : For flushing the store file ( NOT recommended ) ");
printf("\nNow you can enter any one of the modes \n");
printf("\nEnter your choice [ip][op][q to quit]\t");
scanf("%s",buffer);
if(!strcmpi(buffer,"ip"))
input_mode();
else if(!strcmpi(buffer,"op"))
output_mode();
else if(!strcmpi(buffer,"q"))
exit(0);
}
output_mode()
{
FILE *fopen(),
*fp;
char c;
int i;
unsigned short no_bdays = 1;
union bday a;
_dos_getdate(&real_date);
fp = fopen("bdays.dat","r");
fseek(fp,0L,0);
while((c=getc(fp))!=EOF)
{
a.bytes[0]=c;
for(i=1;i<(sizeof(a));i++)
a.bytes[i]=getc(fp);
if(real_date.day == a.date.day && real_date.month == a.date.month)
{
today(a.date.name);
no_bdays=0;
}
}
if(no_bdays)
printf("\nNo Birthdays 2day");
fclose(fp);
}
today(char name[30])
{
int i;
printf("Wish a happy birth day to %s",name);
while(!kbhit())
{
delay(100);
for(i=0;i<strlen(name);i++)
printf("\b");
for(i=0;i<strlen(name);i++)
putchar(' ');
delay(50);
for(i=0;i<strlen(name);i++)
printf("\b");
printf("%s",name);
delay(100);
}
getch();
}
flush_file()
{
FILE *fopen();
FILE *fp;
char buffer[4];
printf("\nDo you really want to flush the file [y]/[n]");
scanf("%s",buffer);
if(*buffer == 'y' || *buffer == 'Y')
{
fp = fopen("bdays.dat","w");
fflush(fp);
printf("\nFile flushed !");
}
}
Bday.c
/* * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* A program using data structures .. *
* Author : Rajesh _ThE gReAt *
* *
* This program uses data structures to store birthdays and if *
* birthday is today prints a message saying so.It has one drawback though *
* it dosen't store birthdays into disk and hence looses them the moment *
* it is removed from ram... *
* Licence : Distributable under GNU public license *
* I hope u keep my name intact.... *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * */
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<rajesh.h>
struct bday
{
char name[30];
int day;
int month;
struct bday *next;
};
struct bday *new_node();
main()
{
struct bday *p,
*list = NULL,
*new_node();
char reply[10]; /* Holds user's reply 'y' or 'n' */
do
{
*p = new_node();
if(*p = NULL)
{
printf("\nNot enough memory...");
*reply = 'n';
}
else
{
get_data(&p);
add_node(&p,&list);
printf("\nAdd another Birtday(y/n) ");
scanf("%9s",reply);
}
}
while(*reply == 'y' || *reply == 'Y');
}
struct bday new_node()
{
struct bday *malloc();
return(malloc(sizeof(struct bday)));
}
get_data(node)
struct bday *node;
{
printf("\nEnter the name:");
gets(node->name);
printf("\nEnter the birthday (Eg.13/11 for 13th november) :");
scanf("%d/%d",node->day,node->month);
return 0; /* Keep compiler happy */
}
add_node(node,list)
struct bday *list;
{
node->next = list;
list = node;
return 0; /* Keep compiler happy */
}