Reputation: 1053
hi im trying to intialize a variable im calling it
int Score;
char Buffer[1024];
im using SDL so to display them i had to convert Score to char
With this im incrementing the score
case SDLK_m:
Score+=1;
break;
and im displaying this with this function
void GetText()
{
itoa (Score,Buffer,1024);
drawString(screen,font2,0,0,"Score: ");
drawString(screen,font2,50,0,Buffer);
}
so when im displaying it it goes like this 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,etc and i want it to normally count like 0,1,2,3,4,5,6,7,8,9,10,11,etc
so what am i doing wrong? any idea?
Upvotes: 0
Views: 651
Reputation: 4163
itoa is defined as follows: char * itoa ( int value, char * str, int base );
The last param is the base, not the buffer size, so in your case you would want to pass in 10
as follows:
itoa(Score, Buffer, 10);
Upvotes: 3