Convert int to char[] I'm looking to convert an int value to a char array. currently I've found the following will return [number]

int num = [number]
str = String(num);
str.toCharArray(cstr,16);
Serial.println(cstr);


However, per Majenko's The Evils of Arduino Strings I feel like this code would make my Arduino's heap look like swiss cheese. Is there a better way to change an [int] into a char[n] array that avoids the String class?
itoa is the best route:

int num = 1234;
char cstr[16];
itoa(num, cstr, 10);
-&gt; "1234"


You can read more about using it here.

If you want more control over the format of the number (and don't mind the increased PROGMEM usage) you can use sprintf (or the more secure snprintf) to format it:

sprintf(cstr, "%05d", num);
-&gt; "01234"


Or with PROGMEM string constant:

sprintf_P(cstr, (PGM_P)F("%05d"), num);
-&gt; "01234"


Or with more values:

sprintf_P(cstr, (PGM_P)F("%02d:%02d:%02d"), hours, minutes, seconds);
-&gt; "03:23:11"