Friday, April 29, 2005
Memory allocation
Here is a code from a book:
char* cDay = " ";
char* cYear = " ";
itoa(m_Calendar1.get_Day(), cDay, 10);
When running it, it gave write access violation. Seems that the memory can't be written. So I changed it to:
char cDD[10];
char cYY[10];
char* cDay = cDD;
char* cYear = cYY;
itoa(m_Calendar1.get_Day(), cDay, 10);
Then it works fine. I don't know how this can be explained. Do you?
char* cDay = " ";
char* cYear = " ";
itoa(m_Calendar1.get_Day(), cDay, 10);
When running it, it gave write access violation. Seems that the memory can't be written. So I changed it to:
char cDD[10];
char cYY[10];
char* cDay = cDD;
char* cYear = cYY;
itoa(m_Calendar1.get_Day(), cDay, 10);
Then it works fine. I don't know how this can be explained. Do you?