I made a function that would allow me to get the current date and put it on a string in YYYY.MM.DD format.

string Date::getCurrentDate(){
char datenew[8];
char currentdate[8];
string s;
int size;
_strdate(datenew);
 
            currentdate[0]=datenew[6];
            currentdate[1]=datenew[7];
            currentdate[2]=datenew[5];
            currentdate[3]=datenew[0];
            currentdate[4]=datenew[1];
            currentdate[5]=datenew[2];
            currentdate[6]=datenew[3];
            currentdate[7]=datenew[4];
 
            size=sizeof(currentdate);
            s.assign(currentdate,size);
            return s;    
}

I keep getting a datenew is corrupted error. Why does this happen?

Recommended Answers

Well according to this the buffer needs to be 9 bytes long. Try changing datenew[8] to datenew[9] .

Jump to Post

All 2 Replies

Well according to this the buffer needs to be 9 bytes long. Try changing datenew[8] to datenew[9] .

commented: Helpful +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.