Converting Between Numbers and Strings

The standard library provides a variety of functions to interpret a numeral string and return a numeric value. These functions are listed in Following Table. 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.

Conversion of numeral strings

Conversion Functions in stdlib.h Functions in wchar.h
String to int atoi( )  
String to long atol( ), strtol( ) wcstol( )
String to unsigned long strtoul( ) wcstoul( )
String to long long atoll( ), strtoll( ) wcstoll( )
String to unsigned long long strtoull( ) wcstoull( )
String to float strtof( ) wcstof( )
String to double atof( ), strtod( ) wcstod( )
String to long double strtold( ) wcstold( )

Conversions between strings and numbers using format strings

Conversion Functions in stdio.h Functions in wchar.h
String to number sscanf( ), vsscanf( ) swscanf( ), vswscanf( )
Number to string sprintf( ), snprintf( ), vsprintf( ), vsnprintf( ) swprintf( ), vswprintf( )