The C language provides several standard library functions that convert numbers of arbitrary types (integer, long, float, and so on) to strings. Here is an example of converting an integer to a string using the Itoa () function:
# include <stdio.h>
# include <stdlib.h>
void Main (void)
{
int num = 100;
Char str[25];
ITOA (num, str, 10);
printf ("The number ' num ' is%d and the string ' str ' is%s./n",
num, str);
}
The itoa () function has 3 parameters: the first parameter is the number to be converted, the second is the target string to write the result of the conversion, and the third is the cardinality used to transfer the number. In the example above, the conversion cardinality is 10. 10: decimal; 2: Binary ...
Itoa is not a standard C function, it is unique to Windows, if you want to write a cross-platform program, use sprintf.
is extended under the Windows platform, the standard library has the sprintf, the function is stronger than this, the use method is similar to printf:
Char str[255];
sprintf (str, "%x", 100); A string that converts 100 to a 16 binary representation.
Function Name: ATOL
Function: Convert string to grow integer number
Usage: Long atol (const char *nptr);
program Example:
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
Long L;
Char *str = "98765432";
L = atol (str); /* Originally for L = Atol (LSTR); */
printf ("string =%s integer =%ld/n", str, L);
return (0);
}
ATOL (Convert string to growth integer)
Correlation function Atof,atoi,strtod,strtol,strtoul
Table header file #include <stdlib.h>
Defines a function long atol (const char *nptr);
The function Description Atol () scans the reference nptr string, skips the preceding space character until it encounters a number or sign to start the conversion, and then encounters a non-numeric or string ending ('/0 ') before ending the conversion and returning the result.
The return value returns the number of long integers after the conversion.
Additional Instructions Atol () with the use of Strtol (nptr, (char**) null,10);
Example/* Converts string A to string B into a number and adds a */
#include <stdlib.h>
Main ()
{
Char a[]= "1000000000";
Char b[]= "234567890";
Long C;
C=atol (a) +atol (b);
printf ("c=%d/n", c);
}
Run c=1234567890
C-language---integer string conversions