It is kind of clumsy. You can get digits starting from the low end, using % 10 (modulus) to isolate the units digit and / 10 (integer divide) to shift the number to the right. You do that in a loop until the int goes down to zero. If the whole thing is zero, you have to set the '0' char yourself, because the loop will not then do the first iteration.
You need to add '0' to each digit to make it an ASCII digit, and you need to store the successive digits in a char array.
You need to append a NUL ('\0') char on the end as a string terminator.
Then you need to reverse the whole string, because the digits came out in reverse order. Alternatively, you can fill the char array from the end, but then you have to copy the whole string (including the NUL) up to the front of the buffer.
If the integer can be negative, you need to remember that, make it positive by subtracting it from zero, and stick a '-' on the end before you reverse it.
Sounds a lot, but the long2str function takes about 20 lines.
Edit: there is a recursive solution too. Going down the required depth, and saving the digits on the way back out, avoids the reverse sequence issue (including the minus sign), and creates the string without padding.
//.. Recursive solution.
//.. Base case.
void l2s_r (char **p, long int n)
{
char d = (n % 10) + '0';
if (n >= 10) l2s_r (p, n / 10);
*((*p)++) = d;
}
//.. Wrapper case.
char *l2s (long int n)
{
static char s[24];
char *p = s;
if (n < 0) { *p++ = '-'; n = 0 - n; }
l2s_r (& p, n);
*p = '\0';
return (s);
}