Original Post
As of now I've implemented a message queue type thing into my app. Recently, however, I found that the following lines were outputting bogus garbage (more specifically ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ).
char* temp = new char[999];
sprintf(temp, "ID is %d", ID);
AddMessage(temp);
delete[] temp;
I also noticed that I was using g_Messages[g_NumMessages] = message (see below) instead of strcpy(). After chaging it to strcpy (as it is in the example below) it now just acts like I'm dereferencing a NULL pointer.
I assume the problem is in AddMessage which is defined as
char* g_Messages[10] = {"", "", "", "", "", "", "", "", "", ""};
int g_NumMessages = 0;
void AddMessage(char* message)
{
if(g_NumMessages == 9)
{
for(int i=0;i<9;i++)
g_Messages[i+0] = g_Messages[i+1];
strcpy(g_Messages[9], "");
if(g_NumMessages > 0)
g_NumMessages--;
}
strcpy(g_Messages[g_NumMessages], message);
g_NumMessages++;
}
Any thoughts as to why? (And please no flames telling me to use std::string, as I dislike having c_str() return a const and I dislike casting out of const variables).
Edited to change i to i+0 because it was giving me italics.
[edited by - ms291052 on January 13, 2004 8:33:27 PM]