1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include "stdlib.h"
#include "string.h"
#include "limits.h"
int main( void )
{
char *res;
char buf[12];
// simple conversion without sign
res = itoa( 568876, buf, 10 );
if( strcmp( buf, "568876" ) ) exit( 1 );
// test if the returned pointer points to the buffer
if( strcmp( res, buf ) ) exit( 1 );
// conversion with sign
res = itoa( -568876, buf, 10 );
if( strcmp( buf, "-568876" ) ) exit( 1 );
// convert upper limit
res = itoa( INT_MAX, buf, 10 );
if( strcmp( buf, "2147483647" ) ) exit( 1 );
// convert lower limit
res = itoa( INT_MIN+1, buf, 10 );
if( strcmp( buf, "-2147483647" ) ) exit( 1 );
// convert to hex
res = itoa( 568876, buf, 16 );
if( strcmp( buf, "8AE2C" ) ) exit( 1 );
exit( 0 );
}
|