How can I pass a long as parameter and get a char array in return?
As with many things in C there are many ways of skinning this particular cat.

All of them rely on you first having made a character array to store the result in - you can't "return" an array from a function.

The simplest, though non-standard, way is to use ltoa(), which is an avr-libc specific function (not part of the standard libc functions):

long myLong = 12345L;
char myCharArray[10]; // Enough room for the answer + 1 NULL char

ltoa(myLong, myCharArray, 10);


The 10 in that function call defines the base to represent the number in - base 10 in this case: decimal.

Another way, which is more portable, is to format the string using snprintf():

snprintf(myCharArray, 10, "%dl", myLong);


In this case the 10 is the maximum length of string to prevent it overrunning the 10-character array we made.

A pure Arduino way of doing it would be to use the dreaded String class:

String myString = String(myLong);
myString.toCharArray(myString, 10);


Again in this example the 10 is the length of the buffer we are copying in to.

And there are more. You could do it manually, character by character using division and modulus operators, for example.