1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <cctype> // tolower
char Text[] = "03 May 2012";
char Temp[256] = {0};
const char * p = Text;
int Day = 0;
int Month = 0;
int Year = 0;
unsigned int Length = strlen(p);
bool strccmp(const char * First, const char * Second) // Like strcmp, but will work with case-different words
{
unsigned int i = 0;
while(1)
{
if(tolower(First[i]) != tolower(Second[i]))
return 1;
if(First[i] <= 0)
break;
++i;
}
return 0;
}
for(unsigned int i = 0; i < Length; ++i)
{
Temp[i] = p[i]; // Copy until you find a space
if(Temp[i] == ' ') // If you 'meet' a space, remove it and stop
{
p += i+1; // Next time continue parsing from here
Temp[i] = 0; break;
}
}
Day = _atoi(Temp); // Here, you've got the day!
unsigned int Length = strlen(p);
for(unsigned int i = 0; i < Length; ++i)
{
Temp[i] = p[i]; // Copy until you find a space
if(Temp[i] == ' ') // If you 'meet' a space, remove it and stop
{
p += i+1; // Next time continue parsing from here
Temp[i] = 0; break;
}
}
Month = 1;
do {
if(!strccmp(Temp,"January"))
break;
++Month;
if(!strccmp(Temp,"February"))
break;
++Month;
if(!strccmp(Temp,"March"))
break;
++Month;
if(!strccmp(Temp,"April"))
break;
++Month;
if(!strccmp(Temp,"May"))
break;
++Month;
if(!strccmp(Temp,"June"))
break;
++Month;
if(!strccmp(Temp,"July"))
break;
++Month;
if(!strccmp(Temp,"August"))
break;
++Month;
if(!strccmp(Temp,"September"))
break;
++Month;
if(!strccmp(Temp,"October"))
break;
++Month;
if(!strccmp(Temp,"November"))
break;
++Month;
if(!strccmp(Temp,"December"))
break;
++Month;
} while(0);
if(Month == 13) { /* Error, invalid month */ }
unsigned int Length = strlen(p);
for(unsigned int i = 0; i < Length; ++i)
{
Temp[i] = p[i]; // Copy until you find a space
if(Temp[i] == ' ') // If you 'meet' a space, remove it and stop
{
p += i+1; // Next time continue parsing from here
Temp[i] = 0; break;
}
}
Year = _atoi(Temp); // Here, you've got the Year!
|