hi all , i need to return the value of tempdate to the main function .... any idea how i can do that ???
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
char* incrementdate(int &func_days_int,char *tempdate)
{
char temp_dat[11],temp_mon[8],temp_year[5];
int cur_dat,cur_mon,cur_year;
temp_dat[0] = tempdate[0];
temp_dat[1] = tempdate[1];
temp_mon[0] = tempdate[3];
temp_mon[1] = tempdate[4];
temp_year[0] = tempdate[6];
temp_year[1] = tempdate[7];
temp_year[2] = tempdate[8];
temp_year[3] = tempdate[9];
cur_dat = atoi(temp_dat);
cur_mon = atoi(temp_mon);
cur_year = atoi(temp_year);
cur_dat = cur_dat + func_days_int;
if (cur_dat > 31 && (cur_mon == 1 || cur_mon == 3 || cur_mon == 5 || cur_mon == 7 || cur_mon == 8 || cur_mon == 10 ))
{
cur_mon = cur_mon + 1;
cur_dat = cur_dat - 31;
}
else if (cur_dat > 30 && (cur_mon == 4 || cur_mon == 6 || cur_mon == 9 || cur_mon == 10))
{
cur_mon = cur_mon + 1;
cur_dat = cur_dat - 30;
}
else if ((cur_dat > 29) && (cur_mon == 2) && ((cur_year%4) == 0))
{
cur_mon = cur_mon + 1;
cur_dat = cur_dat - 29;
}
else if ((cur_dat > 28) && (cur_mon == 2) && ((cur_year%4) != 0))
{
cur_mon = cur_mon + 1;
cur_dat = cur_dat - 28;
}
else if ((cur_dat > 31) && (cur_mon == 12))
{
cur_mon = 1;
cur_dat = cur_dat - 31;
cur_year = cur_year + 1;
}
sprintf(temp_dat,"%d",cur_dat);
sprintf(temp_mon,"%d",cur_mon);
sprintf(temp_year,"%d",cur_year);
strcat(temp_mon,"-");
strcat(temp_mon,temp_year);
strcat(temp_dat,"-");
strcat(temp_dat,temp_mon);
tempdate = temp_dat;
return strdup(tempdate);
}
int main()
{
char delay[9]="05:01:00";
char days[3];
int days_int;
days[0]=delay[0];
days[1]=delay[1];
days_int = atoi(days);
char temporarydate[11]="27-12-2000";
int dd,mm,yy;
incrementdate(days_int,temporarydate);
cout<<"the new date is :"<<temporarydate<<"\n";
}
i have no compiler errors , but the value still remains 27-12-2000 ,it it supposed to be 1-1-2001