Parse Date, Why doesn't this code work?!

Just trying to parse a stupid date, and for some reason it works as it's going a long, but as I parse each subsequent chunk the previous chunks are getting all jacked up. I have no clue why this doesn't work, can ANYONE please help me with this?! It's driving me bonkers.

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
 
#include <cctype>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>

#include <cctype>

#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];

  cout << "\n----Here it looks like it works ---" << endl;

    strcpy(buffer, date.c_str());
    strcpy(day, strtok(buffer,"/"));

    cout << "DAY: " << day << endl;

    strcpy(buffer, date.c_str());

    strcpy(buffer, ((strrchr(date.c_str(),'/')),(strchr(date.c_str(), '/') + 1)));
    strcpy(month, strtok(buffer,"/"));
    cout << "MONTH: " << month << endl;


    strcpy(buffer, date.c_str());

    strcpy(year, strrchr(date.c_str(), '/'));
    for(int i = 0; i < 5; i++)
    {
        year[i] = year[i + 1];

    }
    cout << "YEAR: " << year << endl;


    cout << "\n---Here it's messing up --------" << endl;

    cout << "DAY: " << day << endl;
    cout << "MONTH: " << month << endl;
    cout << "YEAR: " << year << endl;



cout << "-------- End Function Call ------" << endl;

}
Last edited on
Topic archived. No new replies allowed.