Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Need help with input_feild();

This thread is locked; no one can reply to it. rss feed Print
Need help with input_feild();
Doctor Cop
Member #16,833
April 2018
avatar

I want to create a function which accepts's key presses and displays them in a rectangular box (field).
I tried a logic which failed because a char cannot be converted to a string.

here's the logic.
char str*;
str = 'a' + event.keyboard.keycode - 1;

Here's my updated version but still not working. showing signs of memory leak, Please Help!

#SelectExpand
1int input_field(int x1, int y1, int x2, int y2, ALLEGRO_COLOR colorU, float boundry, ALLEGRO_COLOR boundry_color, ALLEGRO_FONT *font, ALLEGRO_EVENT &event, ALLEGRO_EVENT_QUEUE *ev_queue) 2{ 3 int x=0; 4 al_draw_filled_rounded_rectangle(x1, y1, x2, y2, 10, 10, colorU); 5 al_draw_rounded_rectangle(x1, y1, x2, y2, 10, 10, boundry_color, boundry); 6 7 if(event.mouse.x >= x1 && event.mouse.x <= x2 && event.mouse.y >= y1 && event.mouse.y <= y2 && event.mouse.button & 1 && event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) 8 { 9 char* str1; 10 //int p=0; 11 while(1) 12 { 13 al_draw_text(font, al_map_rgb(0, 153, 0), x1+5+x, y1+5, 1, "|"); 14 al_wait_for_event(ev_queue, &event); 15 switch(event.keyboard.keycode) 16 { 17 case 1: 18 strcat(str1, "a"); 19 break; 20 case 2: 21 strcat(str1, "b"); 22 break; 23 case 3: 24 strcat(str1, "c"); 25 break; 26 case 4: 27 strcat(str1, "d"); 28 break; 29 case 5: 30 strcat(str1, "e"); 31 break; 32 case 6: 33 strcat(str1, "f"); 34 break; 35 case 7: 36 strcat(str1, "g"); 37 break; 38 case 8: 39 strcat(str1, "h"); 40 break; 41 case 9: 42 strcat(str1, "i"); 43 break; 44 case 10: 45 strcat(str1, "j"); 46 break; 47 case 11: 48 strcat(str1, "k"); 49 break; 50 case 12: 51 strcat(str1, "l"); 52 break; 53 case 13: 54 strcat(str1, "m"); 55 break; 56 case 14: 57 strcat(str1, "n"); 58 break; 59 case 15: 60 strcat(str1, "o"); 61 break; 62 case 16: 63 strcat(str1, "p"); 64 break; 65 case 17: 66 strcat(str1, "q"); 67 break; 68 case 18: 69 strcat(str1, "r"); 70 break; 71 case 19: 72 strcat(str1, "s"); 73 break; 74 case 20: 75 strcat(str1, "t"); 76 break; 77 case 21: 78 strcat(str1, "u"); 79 break; 80 case 22: 81 strcat(str1, "v"); 82 break; 83 case 23: 84 strcat(str1, "w"); 85 break; 86 case 24: 87 strcat(str1, "x"); 88 break; 89 case 25: 90 strcat(str1, "y"); 91 break; 92 case 26: 93 strcat(str1, "z"); 94 break; 95 } 96 al_draw_text(font, al_map_rgb(0, 153, 0), x1+10, y1+5, 1, str1); 97 //x+5; 98 //printf("%s", str1); 99 if(event.keyboard.keycode == ALLEGRO_KEY_ENTER) 100 { 101 break; 102 } 103 al_flip_display(); 104 105 } 106 } 107 return 0; 108}

Niunio
Member #1,975
March 2002
avatar

Are you reserving memory space for your str1 string? If you aren't that's why your memory is leaking.

-----------------
Current projects: Allegro.pas | MinGRo

Go to: