OK, I've acheived HULK SMASH levels of frsutration with this one. I simply want to parse a date in the form of ##/##/####
The code below works peicemeal, ie each part SEEMS to work, but if I cout at the bottom the day is dissapearing or spitting out erroneous crap.
#include <cctype>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
using namespace std;
void dateParse(string);
int main()
{
string dte1 = "2/5/2014";
string dte2 = "2/15/2014";
string dte3 = "12/5/2014";
string dte4 = "12/15/2014";
string dts;
dateParse(dte1);
dateParse(dte2);
dateParse(dte3);
dateParse(dte4);
}
void dateParse(string date)
{
char day[2] = "";
char month[2] = "";
char year[5] = "";
char buffer[80] = "";
year = date.substr(date.find("/")+1,date.length());
strcpy(buffer, year.c_str());
strcpy(buffer, date.c_str());
strcpy(day, strtok(buffer,"/"));
strcpy(buffer, date.c_str());
strcpy(year, strrchr(date.c_str(), '/'));
for(int i = 0; i < 5; i++)
{
year[i] = year[i + 1];
}
strcpy(buffer, date.c_str());
strcpy(buffer, ((strrchr(date.c_str(),'/')),(strchr(date.c_str(), '/') + 1)));
strcpy(month, strtok(buffer,"/"));
cout << "DAY: " << day << endl;
cout << "MONTH: " << month << endl;
cout << "YEAR: " << year << endl;
cout << "--------------------------------" << endl;
}
here's my main:
`
#include <cctype>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
using namespace std;
void dateParse(string);
int main()
{
string dte1 = "2/5/2014";
string dte2 = "2/15/2014";
string dte3 = "12/5/2014";
string dte4 = "12/15/2014";
string dts;
dateParse(dte1);
dateParse(dte2);
dateParse(dte3);
dateParse(dte4);
}
This is the output
DAY: 2
MONTH:
YEAR: 2014
DAY:
MONTH:
YEAR: 2014
DAY: 12♣
MONTH:
YEAR: 2014
DAY:
MONTH:
YEAR: 2014
Process returned 0 (0x0) execution time : 0.063 s
Press any key to continue.
The annoying this is if I cout the day month and year right after they're parsed it looks like it's working. Can someone help me parse this stupid date? I inventing new and horrible swear words here.