Help with converting char to *char

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
sesteve
 
Posts: 38
Joined: Thu Nov 17, 2011 10:56 pm

Help with converting char to *char

Post by sesteve »

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)'

============================================================

User avatar
cstratton
 
Posts: 294
Joined: Wed Sep 29, 2010 3:52 pm

Re: Help with converting char to *char

Post by cstratton »

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

    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

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”