Difference between two Dates in C language
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int con(char ch)
{
char *c;
*c=ch;
return atoi(c);
}
int scan(char arr[])
{
int flag=1,i;
int p;
for(i=0;i<=9;i++)
{
if(!((arr[i]>=48 && arr[i]<=57) || arr[i]=='/'))
{
return 0;
}
}
p=con(arr[0])*10+con(arr[1]);
if(p>31)
return 0;
p=con(arr[3])*10+con(arr[4]);
if(p>12)
return 0;
return 1;
}
void sub(char date1[],char date2[])
{
int d1,d2,m1,m2,y1,y2;
d1=con(date1[0])*10+con(date1[1]);
d2=con(date2[0])*10+con(date2[1]);
m1=con(date1[3])*10+con(date1[4]);
m2=con(date2[3])*10+con(date2[4]);
//y1=((( con(arr[6])*10 + con(arr[7]) )*10) + con(arr[8]) )*10) + con(arr[9]);
printf("\n%d/%d \n%d/%d",d1,m1,d2,m2);
}
void main()
{
char date1[11],date2[11];
char *ch;
clrscr();
printf("Enter the first date¯");
scanf("%s",date1);
printf("\nEnter the second date¯");
scanf("%s",date2);
//printf("%d %d",scan(date1),scan(date2));
if(scan(date1)==1 && scan(date2)==1)
{
sub(date1,date2);
}
//printf("%d",a);
getch();
}
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
int con(char ch)
{
char *c;
*c=ch;
return atoi(c);
}
int scan(char arr[])
{
int flag=1,i;
int p;
for(i=0;i<=9;i++)
{
if(!((arr[i]>=48 && arr[i]<=57) || arr[i]=='/'))
{
return 0;
}
}
p=con(arr[0])*10+con(arr[1]);
if(p>31)
return 0;
p=con(arr[3])*10+con(arr[4]);
if(p>12)
return 0;
return 1;
}
void sub(char date1[],char date2[])
{
int d1,d2,m1,m2,y1,y2;
d1=con(date1[0])*10+con(date1[1]);
d2=con(date2[0])*10+con(date2[1]);
m1=con(date1[3])*10+con(date1[4]);
m2=con(date2[3])*10+con(date2[4]);
//y1=((( con(arr[6])*10 + con(arr[7]) )*10) + con(arr[8]) )*10) + con(arr[9]);
printf("\n%d/%d \n%d/%d",d1,m1,d2,m2);
}
void main()
{
char date1[11],date2[11];
char *ch;
clrscr();
printf("Enter the first date¯");
scanf("%s",date1);
printf("\nEnter the second date¯");
scanf("%s",date2);
//printf("%d %d",scan(date1),scan(date2));
if(scan(date1)==1 && scan(date2)==1)
{
sub(date1,date2);
}
//printf("%d",a);
getch();
}
0 comments:
Post a Comment
You are most welcome for making comments here. I will consider your view and will reply you soon.