[SOLVED]Comparing char* from gb.Keyboard()

Understanding the language, error messages, etc.

[SOLVED]Comparing char* from gb.Keyboard()

Postby ajsb113 » Thu Jan 22, 2015 3:13 pm

So I'm trying to implement a code input for my game Maruino and I'm having a bit of trouble comparing the strings that come out of the keyboard method. I would like to have support for the symbols as well, not just the letters. If anybody has ideas or knows how to do this, I'd like some help. :)
Last edited by ajsb113 on Fri Jan 23, 2015 3:24 pm, edited 1 time in total.
User avatar
ajsb113
 
Posts: 45
Joined: Tue Jun 24, 2014 4:47 am
Location: Illinois, United States

Re: Comparing char* from gb.Keyboard()

Postby rodot » Thu Jan 22, 2015 4:06 pm

Hey,

You can use the function strstr to check if one chain is contained into another. I changed the keyboard example for it to check if you entered a smiley face :

Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

char text[13] = "Default text";

void setup(){
  gb.begin();
  gb.titleScreen(F("Keyword example"));
  gb.keyboard(text, 13);
}

void loop(){
  if(gb.update()){
    gb.display.println(F("You wrote:"));
    gb.display.println(text);
   
    if(strstr(text,":)")){
      gb.display.println(F("Nice Smiley!"));
    }

    if(gb.buttons.pressed(BTN_C)){
      gb.titleScreen(F("Keyword example"));
      gb.keyboard(text, 13);
    }
  }
}


Concerning special characters, you can type them in your source code using the octal value of the character in an escape sequence ("\" followed by the octal value). Check the character table to find the code : first is the row number and second the column number. For example "\25\26\27" is the string "A button symbol", "B button symbol", "C button symbol".

Font5x7.png
Font5x7.png (4.32 KiB) Viewed 3169 times
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Comparing char* from gb.Keyboard()

Postby ajsb113 » Thu Jan 22, 2015 9:51 pm

Thanks! I'll try that out. :D
User avatar
ajsb113
 
Posts: 45
Joined: Tue Jun 24, 2014 4:47 am
Location: Illinois, United States


Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 9 guests

cron