Write Access Violation with Itoa

I've never had this kind of problem before, it's just started coming up recently. It seems that no matter what I do, the itoa() function doesn't work correctly for me. Whenever I use it, I get a memory write error. It doesn't seem to matter how I initialize the char variable I'm using to store the data, either.

Here is an example of how I used it last:
1
2
3
4
5
6
7
8
9
10
11
12
void RenderHud()
{
char *player1=player1name,*player2=player2name,*turnstr;
itoa(turn,turnstr,10);
Draw_Str(gamename,Info,(Info.w/2)-(strlen(gamename)/2)-1,0,"white","black",0);
Draw_Str("Turn: ",Info,(Info.w/2)-4,1,"white","black",0);
Draw_Str(turnstr,Info,(Info.w/2)+2,1,"white","black",0);
if(currentplayer==1)
	Draw_Str(player1,Info,0,2,player1color,"black",0);
else
	Draw_Str(player2,Info,0,2,player2color,"black",0);
}

I'm passing turnstr to a function that accepts a const char * as one of its parameters. But first I have to convert the integer turn to a string and store it in turnstr. That's where the memory write error occurs.

I get this same problem with strcpy() and strcat() as well. Any help?
Just so you know, itoa() is a nonstandard function. You need to allocate some space for turnstr before trying to write to it.
Yeah, I tried allocating space first. No matter how much I allocate, I get a memory write error as soon as it's accessed the first time. Is there a specific way I should allocate it?
How are you allocating it? If you are using C++, use new/delete. C, use malloc()/free().
Thank you very much! I just learned something very important about C++. This has been bothering me for a long time, it's a relief to finally figure it out.
Topic archived. No new replies allowed.