rdur, (spoken, it sounds almost like "harder" when you're heavy lifting in a crew)
It's okay to use the functions but know what's behind them, in the case of text it is ACSII codes.
Hang in there, a bit of knowing will remove doubts and hesitations. Get past the mystery all you can!
Note: cripes, by the time I got this together there's 4 other replies already!
int asdf = 12345678;
array qwer[8];
then some code that would render:
qwer(0) = 1
qwer(1) = 2
The number in int asdf is 16 binary bits that equals decimal 12345678 except that decimal 12345678 won't fit in a 16 bit integer! Those can hold -32768 to 32767. When you try more they overflow and that usually makes a code bug which is why it's important to know the limits, this is good info not trivia. 12345678 take a long to hold, just so you know when you need to deal with big integers.
Text is a whole other ballgame. All text chars do hold binary values. What gets shown, otoh, are the corresponding ASCII text characters. Before "look it up on the internet" we used books and every programming book worth having had an ASCII Table in the front or back. It helps to know how the mess is organized.
You can get ASCII into char variables this way:
char textLetter = '0'; // now textLetter == decimal 48
and you can change them or evaluate through math, oh yeah.
textLetter++; // now textLetter == 49 == '1'
textLetter = '9';
byte theNumber = textLetter - '0'; // theNumber == 9, only works right for text '0' through '9'
And always remember that with char array text strings, there has to be a NULL (== 0) char at the end unless you're using your own code that knows where to stop translating. The NULL marks the end for print and most string functions.
But, just for fun, this is tested and you can load it into Arduino and mess with it or cut&paste lines:
#include <stdio.h> // to get sprintf()
#include <stdlib.h> // to get itoa()
void setup( void )
{
Serial.begin( 9600 );
int asdf = 12345;
int saveVal = asdf;
char qwer[ 8 ]; // I give it a little extra room because of the last two examples
int divider = 10000; // work digits high to low, left to right
byte i = 0; // what char in qwer to fill next
byte firstNonZero = 0; // to keep out leading zeros
while ( divider > 0 )
{
if ( firstNonZero == 0 )
{
if ( asdf >= divider )
{
firstNonZero = 1;
}
}
if ( firstNonZero > 0 )
{
qwer[ i++ ] = '0' + ( asdf / divider ); // ++ increments AFTER use
asdf %= divider; // asdf is now the remainder of the division
}
divider /= 10; // move to the next digit
}
qwer[ i ] = 0; // add the NULL string terminator
Serial.println( "\nbehind the text -- numbers" ); // \n is ASCII newline
Serial.println( "hang in there!\n" ); // \n is ASCII newline
Serial.print( "the original int is " );
Serial.println( saveVal );
Serial.print( "the roll your own converted text is " );
Serial.println( qwer );
sprintf( qwer, "%d", saveVal );
Serial.print( "\nthe sprintf converted text is " );
Serial.println( qwer );
itoa( saveVal, qwer, 10 ); // 10 is the radix for decimal result
Serial.print( "\nthe itoa converted text is " );
Serial.println( qwer );
}
void loop( void )
{
}
Here's the AVR LibC (what Arduino IDE uses) library page. Serious-up, bookmark this page!
This IS a final-type go to reference for Arduino. The only "moar" is the source codes in your IDE and even then, these pages have explanations you won't find so easy in the source if at all.
http://www.nongnu.org/avr-libc/user-manual/modules.html
Here is where you will find the stdio library:
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html
And the major part of what you need to know to convert with sprintf, in case you think MY bit of code is long.
But then, sprintf (part of the vprintf family) formats -everything-. It IS good to know eventually.
Just know that "1 line of code" can take a good bit of learning and may generate a lot of actual code.
Look into the format specifiers section, it won't fit this post!