大æ´æ°ç计ç®å¯ä»¥éè¿æ¨¡è¿ç®æ¥è¿è¡ç®åï¼ä¹å¯ä»¥å°å
¶ä½ä¸ºå符串读å
¥ï¼ç¶åå段è¿ç®ä¹ååè¿è¡æ¼æ¥ã
éï¼
atoiåitoaç示è代ç å¦ä¸ï¼
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; int ix;
char buffer[20];
int i = 3445;
long l = -344115L;
unsigned long ul = 1234567890UL;
s = " -9885 pigs";
/* Test of atoi */
ix = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, ix );
_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 );
}
è¾åºç»æï¼
atoi test: ASCII string:
-9885 pigs
integer: -9885
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
温馨提示:答案为网友推荐,仅供参考