Assuming your value is 9999 or less, the approach is
This will produce a string of maximum length 4 (plus an additional zero byte).Code:char buffer[5]; sprintf(buffer, "%lu", value);
If the value is 10000 or more (i.e. 5 or more digits) it won't squeeze into a string of length 4 in a decimal format.