delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/08/05/08:35:48

Message-ID: <398BC3EB.DAFAE384@x-treme.gr>
Date: Sat, 05 Aug 2000 10:36:11 +0300
From: only4usa <only4usa AT x-treme DOT gr>
X-Mailer: Mozilla 4.61 [en] (Win95; I)
X-Accept-Language: el,en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Problems with strings
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019