String and numeric conversion functions in VC

Source: Internet
Author: User
Tags float number ranges
Conversion functions of strings and numbers in VC)

Conversion functions of strings and numbers in VC: atoi, atol, strtodd, strtol, strtoul type conversion

Atoi, atol, strtodd, strtol, and strtoul implement type conversion

Atof (converts a string to a float number)
Related functions
Atoi, atol, strtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Double atof (const char * nptr );
Function Description
Atof () will scan the nptr parameter string, skip the leading space character, and start conversion only when a number or positive or negative sign is encountered, and then when a non-number or string ends ('') and return the result. The nptr string can contain positive and negative numbers, decimal points, or E (e) to represent the exponential part, such as 123.456 or 123e-2.
Return Value
Returns the number of floating point types after conversion.
Additional instructions
The atof () is the same as the use of strtodd (nptr, (char **) null.

Atoi (convert a string to an integer)
Related functions
Atof, atol, atrtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Int atoi (const char * nptr );
Function Description
Atoi () will scan the nptr parameter string, skip the leading space character, and start conversion only when a number or positive or negative sign is encountered, and then when a non-number or string ends ('') and return the result.
Return Value
Returns the number of converted integers.
Additional instructions
Atoi () is the same as using strtol (nptr, (char **) null, 10.

Atol (convert string to integer)
Related functions
Atof, atoi, strtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Long atol (const char * nptr );
Function Description
Atol () scans the nptr parameter string and skips the leading space character until it starts to convert into a number or a positive or negative sign, and then ends with a non-number or string ('') and return the result.
Return Value
Returns the number of converted long integers.
Additional instructions
Atol () and use strtol (nptr, (char **) null, 10); the results are the same.

Gcvt (convert the float number to a string and rounding it out)
Related functions
ECVT, fcvt, sprintf
Header file
# Include <stdlib. h>
Define functions
Char * gcvt (double number, size_t ndigits, char * BUF );
Function Description
Gcvt () is used to convert the parameter number into an ASCII string. The parameter ndigits indicates the number of digits displayed. Gcvt () differs from ECVT () and fcvt () in that the string converted by gcvt () contains the decimal point or positive or negative sign. If the conversion is successful, the converted string will be placed in the space specified by the Buf pointer.
Return Value
Returns a string pointer, which is the Buf pointer.
Additional instructions

Strtodd (convert a string to a floating point number)
Related functions
Atoi, atol, strtodd, strtol, strtoul
Header file
# Include <stdlib. h>
Define functions
Double strtodd (const char * nptr, char ** endptr );
Function Description
Strtodd () scans the nptr parameter string and skips the leading space character. Conversion is started only when a number or positive or negative sign is encountered until a non-number or string ends ('') and return the result. If the endptr value is not null, the character pointer in the nptr that is terminated when an exception occurs is returned by the endptr. The nptr string can contain positive and negative numbers, decimal points, or E (e) to represent the exponent part. Such as 123.456 or 123e-2.
Return Value
Returns the number of floating point types after conversion.
Additional instructions
Refer to atof ().

Strtol (converts a string to a growth integer)
Related functions
Atof, atoi, atol, strtodd, strtoul
Header file
# Include <stdlib. h>
Define functions
Long int strtol (const char * nptr, char ** endptr, int base );
Function Description
Strtol () converts the nptr parameter string to the Growth integer number based on the base parameter. The base parameter ranges from 2 to 36, or 0. The base parameter indicates the base mode. For example, if the base value is 10, the base value is 10. If the base value is 16, the base value is hexadecimal. When the base value is 0, the conversion is made using 10. However, if the '0x 'prefix character is encountered, the hexadecimal conversion is made using 16. At the beginning, strtol () scans the nptr parameter string, skips the leading space character, and starts conversion only when a number or positive or negative sign is encountered, and then ends when a non-number or string ends ('') end the conversion and return the result. If the endptr parameter is not null, the character pointer in the nptr that is terminated due to an exception is returned by the endptr.
Return Value
Returns the converted long integer. Otherwise, the error code is returned and stored in errno.
Additional instructions
The conversion string specified by erange exceeds the valid range.

Strtoul (convert a string to an unsigned long integer)
Related functions
Atof, atoi, atol, strtodd, strtol
Header file
# Include <stdlib. h>
Define functions
Unsigned long int strtoul (const char * nptr, char ** endptr, int base );
Function Description
Strtoul () converts the nptr parameter string to an unsigned long integer value based on the base parameter. The base parameter ranges from 2 to 36, or 0. The base parameter represents the base method. For example, if the base value is 10, the base value is 10. If the base value is 16, the base value is a hexadecimal number. When the base value is 0, the conversion is made using 10. However, if the '0x 'prefix character is encountered, the hexadecimal conversion is made using 16. At the beginning, strtoul () scans the nptr parameter string, skips the leading space string, and starts conversion only when a number or positive or negative sign is encountered, and then ends when a non-number or string ends ('') end the conversion and return the result. If the endptr parameter is not null, the character pointer in the nptr that is terminated due to an exception is returned by the endptr.
Return Value
Returns the converted long integer. Otherwise, the error code is returned and stored in errno.
Additional instructions
The conversion string specified by erange exceeds the valid range.

Toascii (convert an integer to a valid ASCII character)
Related functions
Isascii, toupper, tolower
Header file
# Include <ctype. h>
Define functions
Int toascii (int c)
Function Description
Toascii () converts parameter C to a 7-bit unsigned char value, and the eighth digit is cleared. This character is converted to an ASCII character.
Return Value
Returns the converted ASCII code.

Tolower (converts uppercase letters to lowercase letters)
Related functions
Isalpha, toupper
Header file
# Include <stdlib. h>
Define functions
Int tolower (int c );
Function Description
If the parameter C is an uppercase letter, the corresponding lowercase letter is returned.
Return Value
Returns the converted lowercase letter. If no conversion is required, the C value is returned.
Additional instructions

Toupper (converts lowercase letters to uppercase letters)
Related functions
Isalpha, tolower
Header file
# Include <ctype. h>
Define functions
Int toupper (int c );
Function Description
If the parameter C is a lowercase letter, the uppercase letter of the ing is returned.
Return Value
Returns the converted uppercase letter. If no conversion is required, the C value is returned.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.