I need to convert an int
value to a char
string, I used the following function where score is of type int
.
void updateScore(){
char str[5] = "0";
sprintf(str, "%d", score);
drawString(str);
}
void drawString5x7(char *string){
while (*string)
drawChar5x7(*string++);
}
This seems to work, except this snippet of code is part of a much larger system where I am coding a video game on a microcontroller (MSP430) with limited memory space available. I am able to update the score one time before my game freezes and crashes.
For some reason, whenever I add the sprintf()
function (or other similar functions like snprintf
, or asprintf
), it eats up a lot of the available memory on the MCU.
With the sprintf
functions it compiles at 11407 bytes.
If I comment that single line out, my code compiles at 4714 bytes
I'm not too familiar with converting int
to char
strings, however, I don't think it's supposed to consume that much memory. Any guidance will be much appreciated.