Help with converting char to *char

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Help with converting char to *char

Postby sesteve » Thu Nov 17, 2011 10: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: 1
Joined: Thu Nov 17, 2011 9:56 pm

Re: Help with converting char to *char

Postby cstratton » Thu Nov 17, 2011 11:38 pm

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
User avatar
cstratton
 
Posts: 246
Joined: Wed Sep 29, 2010 2:52 pm


Return to General Project help

Who is online

Users browsing this forum: mibignistinly and 9 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]