"Linux C Chinese function Manual" string conversion function

Source: Internet
Author: User
Tags define function uppercase letter

String Conversion Functions
1) atof converts a string into a floating-point number

Correlation function Atoi,atol,strtod,strtol,strtoul
Table header file #include <stdlib.h>
Defines the function double atof (const char *nptr);
The function Description Atof () scans the parameter nptr string and skips the preceding space character until it encounters a number
The word or positive sign starts the conversion, and then it ends with a non-numeric or string ending (' + ').
and returns the result. The parameter nptr string can contain a sign, a decimal point, or E (e) to represent an exponential part.
such as 123.456 or 123e-2.
The return value returns the number of converted floating-point types.
The additional description atof () is the same as the result of using Strtod (nptr, (char**) NULL).

2) Atoi convert string to Integer


Correlation function Atof,atol,atrtod,strtol,strtoul
Table header file #include <stdlib.h>
Defines the function int atoi (const char *nptr);
The function Description Atoi () scans the parameter nptr string and skips the preceding space character until it encounters a number
The word or positive sign starts the conversion, and then it ends with a non-numeric or string ending (' + ').
and returns the result.
The return value returns the number of integers after the conversion.
Additional instructions atoi () with the use of Strtol (nptr, (char**) null,10);

3) Atol convert string to grow integer number


Off 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 parameter nptr string and skips the preceding space character until it encounters a number
The word or positive sign starts the conversion, and then it ends with a non-numeric or string ending (' + ').
and returns 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);

4) GCVT converts a floating-point number to a string, rounding


Correlation function ecvt,fcvt,sprintf
Table header file #include <stdlib.h>
Defines the function char *gcvt (double number,size_t Ndigits,char *buf);
The function Description GCVT () is used to convert the parameter number to an ASCII string, and the parameter ndigits represents
The number of digits displayed. The difference between GCVT () and ECVT () and FCVT () is that the words converted by GCVT ()
The string contains a decimal point or a positive or negative symbol. If the conversion succeeds, the converted string is placed in the parameter buf pointer
The space referred to.
The return value returns a string pointer, which is the BUF pointer.

5) Strtod convert string to floating point number


Correlation function Atoi,atol,strtod,strtol,strtoul
Table header file #include <stdlib.h>
Defines the function double strtod (const char *nptr,char **endptr);
The function Description Strtod () scans the parameter nptr string, skips the preceding space character until it encounters
The number or positive sign starts the conversion, and ends with a non-numeric or string ending (' + ').
and returns the result. If endptr is not null, the characters in the nptr that are terminated when the condition is encountered are
The pointer is passed back by Endptr. The parameter nptr string can contain a positive sign, a decimal point, or E (e) to represent the exponential portion.
such as 123.456 or 123e-2.
The return value returns the number of converted floating-point types.
Additional instructions refer to Atof ().

6) Strtol convert string to grow integer number


Correlation function Atof,atoi,atol,strtod,strtoul
Table header file #include <stdlib.h>
Defines a function long int strtol (const char *nptr,char **endptr,int base);
The function Description Strtol () converts the parameter nptr string to the number of growth integers based on the parameter base. Parameter
The number base range is from 2 to 36, or 0. The parameter base represents the method in which a base value of 10 is used.
10 binary, if the base value of 16 is used in 16. When the base value is 0, the conversion is made in 10.
However, a 16-binary conversion is used when encountering a pre-character such as ' 0x '. The first strtol () will scan the parameters nptr
String, skipping the preceding space character until a number or sign is encountered to begin the conversion, and then encounters
A non-numeric or string ending (' + ') ends the conversion and returns the result. If the parameter endptr is not NULL,
The character pointer in the nptr that terminates when the condition is encountered is returned by Endptr.
The return value returns the number of converted long integers, otherwise erange is returned and the error code is saved errno
In
Additional instructions Erange The specified conversion string is outside the legal range.


7) Strtoul convert string to unsigned long integer number


Correlation function Atof,atoi,atol,strtod,strtol
Table header file #include <stdlib.h>
Defines a function unsigned long int strtoul (const char *nptr,char
The function Description Strtoul () converts the parameter nptr string to an unsigned long integer based on the parameter base.
Type number. The parameter base range is from 2 to 36, or 0. The parameter base represents the binary
10 If base value is 10, and 16 if base value is 16
such as When the base value is 0, the conversion is made with 10, but encounters a pre-character such as ' 0x '
The conversion is made using the 16 binary. At first Strtoul () scans the parameter nptr string,
Skips the preceding space string until a number or sign is encountered to begin the conversion.
The conversion is again encountered when the non-numeric or string ends (' + ') and returns the result. If
Parameter endptr is not NULL, the characters in nptr that are terminated when they encounter a non-conditional
The pointer is returned by ENDPTR.
The return value returns the number of converted long integers, otherwise erange is returned and the error code is saved errno
In
Additional instructions Erange The specified conversion string is outside the legal range.

8) toascii Converts an integer number to a valid ASCII character


Correlation function Isascii,toupper,tolower
Table header file #include <ctype.h>
define function int toascii (int c)
The function Description Toascii () converts the parameter C to a 7-bit unsigned char value, and the eighth bit is
Cleared, this character is then converted to ASCII characters.
The return value returns the converted ASCII character value for success.


9) ToLower convert uppercase letters to lowercase


Correlation function Isalpha,toupper
Table header file #include <stdlib.h>
Defines the function int tolower (int c);
Function description if the argument c is an uppercase letter, the corresponding lowercase letter is returned.
The return value returns the converted lowercase letter, and if no conversion is required, the parameter C value is returned.
Additional Instructions


ToUpper Convert lowercase letters to uppercase


Correlation function Isalpha,tolower
Table header file #include <ctype.h>
Defines the function int toupper (int c);
Function description if the argument c is lowercase, the uppercase letter of the pair is returned.
The return value returns the converted uppercase letter, and if no conversion is required, the parameter C value is returned.
Additional Instructions

"Linux C Chinese function Manual" string conversion function

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.