How can I convert an integer
to a string
in C and include a leading zero if the integer has only one digit? The result is needed to print to an LCD Display and not to print to console.
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int i = 7;
char buffer[10];
itoa(buffer, i, 10);
printf ("decimal: %s\n",buffer);
return 0;
}
This code would print 7
but i need it to be 07
.
But numbers greater than 10 eg.: 77
should remain the same.