-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Can i ask the question:
If you have an integer(int), how to print it out without using printf?
This looks like a "Programming class" challange/exercise to me.
The solution depends on how strict that "without using printf" directive is.
Strictly speaking, sprintf() isn't printf(). So, you could use sprintf() to
convert the integer into a printable string, then print it using puts() or a
putchar() loop.
However, if you aren't permitted to use sprintf(), you /can/ write your own
integer-to-string conversion function, and use it instead. If you do so, you'll
have to be sensitive to the sign of the source integer, and to handling of
signed integers in general. You'll want something like
char *IntToString(int number, char *string)
{
if (number > 10) /* take care of leading digits */
string = IntToString(number/10,string);
*string++ = '0' + (number%10);
*string = '\0';
return string;
}
but with logic to properly manage negative numbers.
- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)
iD8DBQFAh+PMagVFX4UWr64RAoY9AJ4170vcYACQj5U2gd+t99eDDHFinACg2PdC
QXnrszOfTBKdphrMG9q+ehY=
=qVa4
-----END PGP SIGNATURE-----