Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert char* to long
How to convert char* to long
The conversion from char* to long can be realized by the first address of the string.

These three functions are listed in the Itoa ltoa ultoa header file.

Its prototype:

Char *itoa (integer value, char * string, integer radix)

Cahr *ltoa (long value, character * string, integer radix)

Char *ultoa (unsigned long integer, char *string, int radix)

Value is the number to be converted.

String string result

The radix of a radix value.

It is obvious that:

I is int, l is long, and ul is unsigned long.

When the quantity is small, it doesn't matter if you use it wrong.

Description:

This type of function converts a value into a string ending in a space and stores it in a string (up to 33 bytes) without performing overflow checking.

Radix represents the radix of the value, and radi must be in the range of 2-36.

Example:

# include & ltstdlib.h & gt

# Include & ltstdio.h & gt

Invalid master (invalid)

{

A charging buffer [20];

int i = 3445

Dragon l =-344115;

Unsigned length ul =1234567890;

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 (radix10)": 0x%s/n ",l, buffer);

ultoa( ul,buffer, 16);

Printf ("unsigned long string %lu (radix 10): 0x%s/n", ul, buffer);

}

output

Integer string 3445 (radix 10): 3445

Integer string 3445 (radix 16): 0xd75

String of integer 3445 (radix 2):1111101

Long integer string -344 1 15 (radix 10):0x fffabbcd.

Unsigned long integer string 1234567890 (radix 16): 0x499602d2