Mail Archives: djgpp/2000/08/05/08:35:48
I have this program that converts a string to date. Most of the time it
does it correctly but some times it gives wrong values. I run the
program from a DOS box (i can only run it from a DOS box). That
subroutine the main program calls it about 2000 times per execution and
sometimes it reports wrong values. Can someone help me?
The input string is declared as "hmeromhnia[8]" in the main program and
as char *string here.
And the format of hmeromhnia[8] is xxyyzzzz where xx is the date yy the
month and zzzz the year.
Here is the program:
void date_str(char *string, int *day, int *month, int *year)
{
int i;
char c, c1[2], c2[2], c3[4];
for(i = 0;i < 2;i++)
{
c = string[i];
c1[i] = c;
}
for(i = 2;i < 4;i++)
{
c = string[i];
c2[i - 2] = c;
}
for(i = 4;i < 8;i++)
{
c = string[i];
c3[i - 4] = c;
}
if (c1[0] == '0')
{
c = c1[1];
*day = atoi(&c);
}
else
*day = atoi(c1);
if (c2[0] == '0')
{
c = c2[1];
*month = atoi(&c);
}
else
*month = atof(c2);
*year = atoi(c3);
}
- Raw text -