The compiler (xc8 and others, most of them) has built in functions that do this job for you.
For example, open the XC8 user guide and search for sprintf or vsprintf ... then read the explanations for printf which explain how that function works.
xc8 user guide here:
http://ww1.microchip.com/downloads/en/DeviceDoc/52053B.pdf If you don't want to add a lot of code to your program and you only need to print a number, you can make one yourself.
something like this
unsigned char digit[
5]; // happy now? sigh... must get some sleep.
unsigned byte digitpos = 5;
unsigned int number = 12345; // your number
unsigned int temp;
unsigned int remainder;
temp = number;
digit[4]=0;
while (temp > 0) {
digitpos--;
digits[digitpos] = temp mod 10;
temp = temp / 10;
}
if (digitpos==5) digitpos = 4;
so you have temp = 12345 , an array with 5 elements [ -, -, -, -, 0] , digitpos = 5;
temp > 0, yes it's 12345 => digitpos--; => digitpos = 4; digit[digitpos] = 12345 mod 10 = 5; = > array is [-,-,-,-5] , temp = temp / 10 = 1234
temp > 0, yes it's 1234 => digitpos--; => digitpos = 4; digit[digitpos] = 1234 mod 10 = 4; = > array is [-,-,-,4,5] , temp = temp / 10 = 123
and so on,
and then you do a for (i = digitpos, i<5, i++) print character digit [ i];
The above code should work with unsigned byte, unsigned char, unsigned int variables. int is maximum 65535 (5 digits). If you want to print larger numbers, you need to increase the array and redefine the digitpos to new value ( for example for a long variable (4 bytes) the maximum value would be 4,294,967,296 so you need to be able to store 10 digits.
There are other methods that use less cpu clocks, for example see the example towards the bottom of this page, which uses shift instead of divisions and precalculated tables (faster but may use more memory) :
http://stackoverflow.com/questions/3694100/converting-to-ascii-in-cor this code which converts any float, integer etc into a series of characters ... so you don't need to use sprintf but you'd neet to use the math library, for log10 and pow functions (xc8 has them)
http://stackoverflow.com/questions/2302969/how-to-implement-char-ftoafloat-num-without-sprintf-library-function-i/2303798#2303798