The following is the C language of the conversion of strings and numbers to implement the code for the analysis, the need for friends can refer to the
1. Convert numbers to Strings
sprintf is almost the same as printf in usage, except that the print destination is different, the former is printed to a string, and the latter is printed directly on the command line.
sprintf is a variable parameter function, defined as follows:
int sprintf (char *buffer, const char *format [, argument] ...);
In addition to the first two parameter types are fixed, any number of parameters can be followed.
Both printf and sprintf use a formatted string to specify the format of the string, using some format specifiers that begin with a "%" (formatted specifications) to occupy a position, and to provide the corresponding variable in the list of arguments in the back. The final function replaces the descriptor with the corresponding position variable to produce a string that the caller wants.
If you print the integer 123 into a string, save it in S.
sprintf (S, "%d", 123);//produce "123"
2. Converting strings to numbers
function Name: ATOL
Function: Converts strings to grow integer numbers
Usage: Long atol (const char *nptr);
program Example:
Copy Code code as follows:
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
Long L;
Char *str = "98765432";
L = atol (str); /* Originally L = Atol (str); */
printf ("string =%s integer =%ldn", str, L);
return (0);
}