Ilya Leshkinov
Ilya Leshkinov

Reputation: 101

Arduino Convert int to Char

i have a value q that is int and can arrive only in range of 0 - 9. and i have the sending function that needs a char value to work. i need to convert the q to char value and send it.

the code im using there:

int q = 5;

//need to convert q to char c
//typicaly like so 'q'
//

Write(c,'!');

if im using something like that c[1] = '\(q)'; i getting error from arduino app:

invalid conversion from 'char*' to 'char' [-fpermissive]

so how can i solve it?

Upvotes: 0

Views: 8829

Answers (2)

MikeCAT
MikeCAT

Reputation: 75062

Try this:

char c;
int q = 5;

c = q + '0'; // convert the number to a character corresponding to it

Upvotes: 1

i486
i486

Reputation: 6573

Write((char)q, '!'). Sounds like very simple question or maybe I have not understood it.

Upvotes: 0

Related Questions