Help with converting char to *char
Moderators: adafruit_support_bill, adafruit

Help with converting char to *char

by sesteve on Thu Nov 17, 2011 11:05 pm

I am trying to read a string of text from text sent from an android phone to a bluesmirf silver mate.
I am using the code below to read a character from the serial and it puts it into a varaiable vl.
I want to send the text to the tft via testdrawtext ... however, if I put a string "info" in place of vl
it works fine but I am having problems sending a letter or number that is vl.
Is there a way to in arduino c to convert vl to a string?

Thank you.

============= code ============================
char vl ;

void loop()
{
vl = bluetooth.read();
testdrawtext(vl, YELLOW);
}

These are the errors I get:

error: invalid conversion from 'int' to 'char*'
error: initializing argument 1 of 'void testdrawtext(char*, uint16_t)'

============================================================
sesteve
 
Posts: 3
Joined: Thu Nov 17, 2011 10:56 pm

Re: Help with converting char to *char

by cstratton on Fri Nov 18, 2011 12:38 am

A char* is a pointer to a string or array of char's. Conventionally, a string of this type must be terminated by a null (0) byte.

You can do something like this:
Code: Select all | TOGGLE FULL SIZE
    char s[2];                       //create an array of two single-byte characters
    s[0] = bluetooth.read();   //put single character in first element of array
    s[1] = 0;                        //null terminate
    testdrawtext(s, YELLOW); //display the string
User avatar
cstratton
 
Posts: 254
Joined: Wed Sep 29, 2010 3:52 pm