16.6. Converting Between Numbers and StringsThe standard library provides a variety of functions to interpret a numeral string and return a numeric value. These functions are listed in Table 16-18. The numeral conversion functions differ both in their target types and in the string types they interpret. The functions for char strings are declared in the header stdlib.h, and those for wide strings in wchar.h.
The functions strtol( ), strtoll( ), and strtod( ) can be more practical to use than the corresponding functions atol( ), atoll( ), and atof( ), as they return the position of the next character in the source string after the character sequence that was interpreted as a numeral. In addition to the functions listed in Table 16-18, you can also perform string-to-number conversions using one of the sscanf( ) functions with an appropriate format string. Similarly, you can use the sprintf( ) functions to perform the reverse conversion, generating a numeral string from a numeric argument. These functions are declared in the header stdio.h. Once again, the corresponding functions for wide strings are declared in the header wchar.h. Both sets of functions are listed in Table 16-19.
|