Well wrote the code but still I have some problems, so could someone help me plz.
void ageCalculator()
{
char birth[BIRTH],output[OUT];
static int finished,d[2],m[2],y[4],days,flag;
int i;
/*initialization of arrays*/
for(i=0;i<11;i++)
{
birth='\0';
if(i<6)
output='\0';
}
printf("\n Age Calculator\n");
printf("-------------------\n");
/* code to get and validate the input*/
do {
flag=FALSE;
do {
finished=0;
printf("\nEnter your date of birth (dd/mm/yyyy format): ");
fgets(birth, BIRTH+ 2, stdin);
if (birth[strlen(birth) - 1] != '\n')
{
printf("Input was too long.\n");
readRestOfLine();
}
else
{
birth[strlen(birth) - 1] = '\0';
if(strlen(birth)==0)
return ;
finished = TRUE;
}
} while (!finished);
/*flag=valid(birth,d,m,y,0);*/
/*flag = TRUE;
if (!flag)
{
printf("\n invalid input");
printf("\nwhere.....");
d[0]=0;
m[0]=0;
y[0]=0;
}*/
}while(flag==FALSE);
/* code to get and validate the input*/
do {
flag=FALSE;
do {
finished=FALSE;
printf("\nEnter your date of birth (dd/mm/yyyy format): ");
fgets(birth, BIRTH+ 2, stdin);
if (birth[strlen(birth) - 1] != '\n') {
printf("Input was too long.\n");
readRestOfLine();
}
else{
birth[strlen(birth) - 1] = '\0';
if(strlen(birth)==0)
return;
finished = TRUE;
}
} while (!finished);
/*flag=valid(birth,d,m,y,1);
*/if (!flag)
{
printf("\n invalid input ");
d[0]=0;
m[0]=0;
y[0]=0;
}
}while(flag==0);
if(y[0]==y[1])
{
days=countm(d,m,y);
}
else
{
days=county(d,m,y);
}
printf(output,"%d",days);
strcpy(output,"");
printf("\n%s\n\n");
}
int county(int d[],int m[],int y[])
{
int i,days=0,tempd[2],tempm[2],temp[2];
for(i=y[0]+1;i<y[1];i++)
{
days+=365;
temp[0]=i;
if(isleapyear(temp))
days+=1;
}
tempd[0]=d[0];
tempd[1]=31;
tempm[0]=m[0];
tempm[1]=12;
days+=countm(tempd,tempm,y);
tempd[0]=1;
tempd[1]=d[1];
tempm[0]=1;
tempm[1]=m[1];
y[0]=y[1];
days++;
days+=countm(tempd,tempm,y);
return days;
}
/*calculating the number of days if months are different*/
int countm(int d[],int m[],int y[])
{
int cal[12]={31,28,31,30,31,30,31,31,30,31,30,31},days,i;
if(m[0]==m[1])
{
days=d[1]-d[0];
}
else if(m[0]!=m[1]) {
days=0;
for(i=m[0]+1;i<m[1];i++)
days+=cal[i-1];
days=days+(cal[m[0]-1]-d[0])+d[1];
if((m[0]<=2&&m[1]>2)&& isleapyear(y))
days++;
}
return days;
}
/*code for calculating whether the given year is leapyear or not*/
int isleapyear(int y[])
{
if((y[0]%4==0)&&((y[0]%100!=0)||(y[0]%400==0)))
return 1;
else
return 0;
}