Variable Length Integer Display Problem

Hi I'm new to embedded programming and am having a problem displaying unsigned integers on a 14 segment starburst display (of 6 displays).

Backgrund
The max value displayed should therefore be 999999 anything more should show out of range.
Any value smaller than this should be shown with no leading zeros (so 34 should be displayed as 34 not 000034).
0 should be displayed.
The display interface which I cannot change is a char buffer of length 12, which validates/converts and displays valid ascii characters ( a-z, A-Z, 0-9 + some special ).

There are no C/C++ library functions such as itoa() available.

Currently I am dividing the initial integer by 10 repeatedly then using the appropriate sprintf() call depending upon how many displays I want to write to.
Unfortunately this doesn't seem to work with anything over 99, 999 the top digit isplays as blank and also seems rather an unsatisfactory solution.

Any suggestions from someone with more experience would be greatly appreciated.
Thanks.

If you can use sprintf(), why are you doing any divisions? You could just do sprintf(buffer,"%d",value);.
Hi I have used sprintf( buffer, "%1d", value ); which does give me the full range of values without padding zeros however the numbers are in the opposite order on the display.

Such that the least significant digit now starts on the left of the display with more significant numbers in ascending order on the right. Unfortunately I need the opposite and haven't managed to reverse them again without introducing zero padding.
How about this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
char temp[12];
size_t l;

sprintf( buffer, "%d", value );
memset(temp,' ',12)
l=strlen(buffer);
memcpy(temp+12-l,buffer,l);
/*
Note: you may need to change a few constants above if the interface requires the
buffer to be null-terminated.
*/
for (size_t a=0;a<12;a++)
	buffer[11-a]=temp[a];
/*
Now, for an input of 123, buffer will contain
{'3','2','1',' ',' ',' ',' ',' ',' ',' ',' ',' '}
*/
Topic archived. No new replies allowed.