handling strings via bluetooth

greetings,
i’m trying to handle strings sent from android bluetooth to the arduino and vise versa.
for example if i send from the android string “hello” i can see it clearly at the serial port, however i can’t deal with this string to “string compare” it for example to do an action or something, where i can only read single characters by serial read which are translated to asci code.
that’s for recieving from the android to the arduino.
as for transmitting from the arduino to the android, i’m trying to get data from the serial port which is a hexadecimal reading of an infrared reciever and send this data as a string via bluetooth, where i use fprint to convert the hexadecimal which is “unsigned long int” to “string” but when i send this via bluetooth i get nothing or boxes.
NOTE:

   #include <SPP.h>

#include <IRremote.h>

USB Usb;
BTD Btd(&Usb);
SPP SerialBT(&Btd); 

 IRsend irsend;
boolean firstMessage = true;
int i=0;
int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  Serial.begin(115200);  
 irrecv.enableIRIn(); 

  if (Usb.Init() == -1) {
    Serial.print(F("\r\nOSC did not start"));
    while(1); //halt
  }
  Serial.print(F("\r\nSPP Bluetooth Library Started"));
}







void loop() {
  Usb.Task();
  if(SerialBT.connected) {
    if(firstMessage) {
      firstMessage = false;
      SerialBT.println(F("Hello from Arduino")); // Send welcome message
    }
    if(Serial.available())
    {
      SerialBT.print(Serial.read());      
    }
    
    
    if(SerialBT.available())
    {  Serial.write(SerialBT.read());
    // delay(100);
    int a=0;
    char c;
    a=SerialBT.read();
   // c=SerialBT.read();
    SerialBT.println(a);       
    }  
} 
  else 
    firstMessage = true;
    
    
    
    if (irrecv.decode(&results)) {
    Serial.print(results.value, HEX);
    char buf[50];    
   sprintf(buf, "test",results.value,HEX);
   SerialBT.println(buf);
   // i get test and nothing then//
   
    irrecv.resume();  
  }      
}

Try #7 below:

http://arduino.cc/forum/index.php/topic,148850.0.html

Your code

is really hard

to

read

White space is good to separate sections of code, but not acres of it, seemingly at

random.

It would also be better if it were in [code ] tags when pasted here. Highlight the code and click the # button above the smileys

As to your question, in order to do a comparison you need the incoming characters to be all in one variable. The preferred way to do this is to put each of them into an array as they arrive and then deal with the array as a whole when receipt of the message is complete.

I don't know much about sprintf but your use of it looks wrong to me. What you are doing looks more like an attempt to use the Serial.print syntax for printing in HEX

Actually i have put this code because it is the simplest of my attempts, but i have tried to use characters arrays and all sorts of these things for the first part but i have fialed. this question requires c programming experience and u don't need actually to understand everything in this code like the bluetooth and infrared libraries.