Pages: [1]   Go Down
Author Topic: Is it possible to convert a int into a string?  (Read 376 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using a Seeed Studio TouchShield. I want to display an int on the screen. But the code only allows me to print chars and strings. I want to know if I can convert a int into a string or char. Basically what I'm asking do the following:
int=1, int=sting/char, string/char=1. Is this possible?
Logged

Offline Offline
Edison Member
*
Karma: 32
Posts: 1382
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure, check out itoa()
http://playground.arduino.cc/Code/PrintingNumbers
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is there an easier way to do this?
Logged

France
Offline Offline
God Member
*****
Karma: 34
Posts: 984
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the number is between 0 and 9 then you can do
Code:
char c = number + '0';

If number is bigger then no there is not an easier solution than itoa, but there is another solution that is sprintf
Code:
char string[12];
sprintf( string, "%d", number );
print( string );
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3357
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is there an easier way to do this?

How much easier are you looking to get?
Logged

Pages: [1]   Go Up
Jump to: