Re: convert int to string without using standard library (stdio.h)
- From: Mark McIntyre <markmcintyre@xxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 23:55:09 +0100
On 17 Jul 2006 15:42:50 -0700, in comp.lang.c , "ceeques"
<cquestions@xxxxxxxxx> wrote:
Thanks for the repy:
I need to convert number (int, short) to a string but cannot use
sprintf as I am using an embedded system. I want to mix text and
number in a display function on the system's output (It doesn't support
printf) but it does have a text to screen function that accepts
strings. I would like to display counters with a message along with it.
Hope my question is clear now.
If you have a single-digit number, you can convert it into the
equivalent character by adding '0'
int i = 4;
char x = i + '0'; // x will be '4'
If you have more than one digit, you would have to apply this logic
iteratively over each digit in turn.
To handle floating point types, you'd need to convert to scaled
integers, and re-insert the decimal point as appropriate.
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
.
- References:
- Prev by Date: Re: convert int to string without using standard library (stdio.h)
- Next by Date: Re: Function declaration without parameters
- Previous by thread: Re: convert int to string without using standard library (stdio.h)
- Next by thread: Re: convert int to string without using standard library (stdio.h)
- Index(es):
Relevant Pages
|