Reputation: 11
I'm developing a pacman game with allegro (in Ubuntu) but I am unable to show the score. I found this code but it doesn't work. Could you help me please?
char scoretxt[10];
printf(scoretxt,"score: %d",score);
textout_ex(buffer, font, scoretxt, TILE_SIZE*(MAP_WIDTH)*3/4, TILE_SIZE, makecol(255,255,255), makecol(0,0,0));
Upvotes: 1
Views: 92
Reputation:
You should be using snprintf
, not printf
:
snprintf(scoretxt, 10, "score: %d", score);
Here the 10
is the length of the buffer scoretxt
to ensure that snprintf
doesn't write outside the allocated array.
Upvotes: 5