Program to find date, month and year.

#include<stdio.h>

char* reverse(char *s1)
{
char *c1,*c2,ch;
for(c1=s1,c2=&s1[strlen(s1)-1];c1<c2;c1++,c2--)
{
ch=*c1; *c1=*c2;  *c2=ch;
}
return(s1);
}

char *strdate(int *ptr,char *arr)
{
char da[29],ye[4],*mo[12]={"JANUARY ","FEBRUARY ","MARCH ","APRIL ","MAY ","JUNE ","JULY ","AUGUST ","SEPTEMBER ","OCTOBER ","NOVEMBER ","DECEMBER "};
int d=ptr[0],y=ptr[2],m=ptr[1],i;
int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char *abc;

strcpy(arr,"");
if(d==0 && m==0 && y==0)return(arr);
if((d<=0 || d>month[m-1]) || (y<0 ||y>99) || (m<=0 || m>12))
{
arr[0]=arr[1]=arr[3]=arr[4]=arr[5]='?';arr[2]=arr[6]=' ';
for(i=7;i<=10;i++)arr[i]='?'; arr[11]='';return(arr);
}
i=0;
while(d)
{
da[i++]=(d%10)+'0';
d=d/10;
}da[i]='';reverse(da);da[i]=' ';da[i++]='';
i=0;
while(y)
{
ye[i++]=(y%10)+'0';
y=y/10;
} ye[i]='';reverse(ye);ye[i]=' ';ye[i++]='';
strcat(da,mo[m-1]);
strcat(da,ye);
return(strcpy(arr,da));
}

main()
{
char arr[30];
int date_arr[3];
printf("\nEnter the date: ");
scanf("%d %d %d",&date_arr[0],&date_arr[1],&date_arr[2]);
strdate(date_arr,arr);
puts(arr);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s