Hi, I create kind od board game in Allegro and I want input numbers and dispplay these numbers on the screen. I try using sscanf and sprintf but still numbers dont display on the screen.
int width = 0;
int length = 40;
char buff[256];
char buff1[256];
char a;
if(key[KEY_RIGHT])
{
if(width<=340)
{
clear_to_color(buffer,makecol(255,255,0));
width+=40;
blit(pole1,buffer,0,0,width,length,40,40);
clear_to_color(pole1,makecol(128,0,0));
sscanf(buff,"%d",&a);
textout_ex(buffer,font,buff,width+20,length+20, makecol(255, 0, 128),-1);
rest(100);
Personally I do not see how you enter the numbers in the 'buff'.
Possibly 'fgets' or 'getline' are missing in your source code.
If I was programming this without the standard C functions I would do it like this:
I don't understand this code at all. Can you describe please what are you doing in this code?
I just avoided all the buffer stuff and converted to const char* using .c_str() then outputted that using al_draw_text.
What doing this program? I creating sudoku game and I want to input numbers into the grid from keypad
Turn Numlock on and monitor ALLEGRO_EVENT_KEY_CHAR events.
Yeah, possibly your num pad lock is off.
if you wish a complete example program this should help (once you run this program you should see two windows - one with text showing the key you pressed and one with graphics that shows different color depending on the key pressed):
MikiZX, note - you have a void function returning 0. I assume you meant to call the function and then return 0.
Thanks Edgar, fixed now.
@Kokxxx12, I hope this can help in some way - if you still have difficulties understanding how it works then please let us know which part you do understand and we will explain the rest.
It might be time to point out that the OP is using A4, not A5.
I need fucking glasses.
Kokxxx12, with Allegro 4 you can use readkey and shift the value 8 bits to get the keycode, then convert it to a number or digit.
oops.. glasses for me too then. Sorry Kokxxx12, now I understand why the code was not understandable.
I don't think I will be able to help with A4 though.
@LennyLen, thank you for pointing this out.