Skip to main content
GameDev.net gamedev.net
🔒 Locked

itoa

Started by randomDecay Nov 12, 2001 at 9:27 PM 5 replies 600+ views
Original Post
randomDecay
randomDecay
I understand how to use atoi, but what about itoa? Can someone give me a run-down on how to use it and the prototype and all that? thanks
EddieCai
EddieCai
Example

/* ITOA.C: This program converts integers of various
* sizes to strings in various radixes.
*/

#include
#include

void main( void )
{
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;

_itoa( i, buffer, 10 );
printf( "String of integer %d (radix 10): %s\n", i, buffer );
_itoa( i, buffer, 16 );
printf( "String of integer %d (radix 16): 0x%s\n", i, buffer );
_itoa( i, buffer, 2 );
printf( "String of integer %d (radix 2): %s\n", i, buffer );

_ltoa( l, buffer, 16 );
printf( "String of long int %ld (radix 16): 0x%s\n", l,
buffer );

_ultoa( ul, buffer, 16 );
printf( "String of unsigned long %lu (radix 16): 0x%s\n", ul,
buffer );
}


Output

String of integer 3445 (radix 10): 3445
String of integer 3445 (radix 16): 0xd75
String of integer 3445 (radix 2): 110101110101
String of long int -344115 (radix 16): 0xfffabfcd
String of unsigned long 1234567890 (radix 16): 0x499602d2
randomDecay
randomDecay
Thanks guys, but I heard you had to use strrev or something to do itoa ? Hmm
Oluseyi
Oluseyi
quote:
Original post by randomDecay
Thanks guys, but I heard you had to use strrev or something to do itoa ? Hmm

Nope. strrev() reverses a string; it has nothing to do with converting integers to character strings.




I wanna work for Microsoft!
randomDecay
randomDecay
do you have a reference for strrev()? I can''t find it anywhere. Thanks
Oluseyi
Oluseyi
It''s in MSDN.



I wanna work for Microsoft!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.