Categories
C Programming Development

Commonly used strings in c-number function

atof(To convert a string into a floating-point number)

Related Functions atoi,atoll,strtod,strtol,strtoul
Header Files #include <stdlib.h>
Defined Functions double atof(const char * nptr);

Function Description atof()It scans the string parameter nptr,Skip over white space characters,Until a few metWord or the sign began to do the conversion,The encounter ended when non-numeric or string(‘/0’)Before the end of conversion,And the results returned。Parameter may include the positive and negative string nptrnumber、Decimal or E(e)To represent the exponent part,123.456 or 123e-2。

return value Floating-point conversion after the return。

Additional information atof()And use strtod(nptr,(char**)NULL)Same result。

atoi(Converting the string to integer)

Related Functions atof,atoll,atrtod,strtol,strtoul
Header Files #include<stdlib.h>
Defined Functions int atoi(const char * nptr);

Function Description atoi()It scans the string parameter nptr,Skip over white space characters,Until you meet numbers or the sign began to do the conversion,The encounter ended when non-numeric or string(‘/0’)Before the end of conversion,And the results returned。

return value After the return integer conversion。

Additional information atoi()And use strtol(nptr,(char**)NULL,10);Same result。

atoll(Converts a string grow integer)

Related Functions atof,atoi,strtod,strtol,strtoul
Header Files #include
Defined Functions long atoll(const char * nptr);

Function Description atoll()It scans the string parameter nptr,Skip over white space characters,Until you meet numbers or the sign began to do the conversion,The encounter ended when non-numeric or string(‘/0’)Before the end of conversion,And the results returned。

return value Long integer returned after conversion。

Additional information atoll()And use strtol(nptr,(char**)NULL,10);Same result。

gcvt(To convert floating-point number to a string,Take rounding)

Related Functions ecvt,fcvt,sprintf
Header Files #include
Defined Functions char *gcvt(double number,size_t ndigits,char *buf);

Function Description gcvt()It used to convert parameters into an ASCII string number,Parameters ndigits number of digits displayed。gcvt()And ecvt()And fcvt()Difference is that,gcvt()The string conversion contains a decimal point or the sign。If the conversion is successful,The converted string will be placed on the spatial parameters buf pointer。

return value Returns a pointer to a string,This address is a pointer to buf。

strtod(Converting the string to float)

Related Functions atoi,atoll,strtod,strtol,strtoul
Header Files #include
Defined Functions double strtod(const char * nptr,char **endptr);

Function Description strtod()It scans the string parameter nptr,Skip over white space characters,Until you meet numbers or the sign began to do the conversion,When non-numeric or string that appears to end(‘/0’)Before the end of conversion,And the results returned。If endptr not NULL,The character pointer will encounter substandard conditions in nptr terminated by endptr return。Parameter may comprise sign string nptr、Decimal or E(e)To represent the exponent part。123.456 or 123e-2。

return value Floating-point conversion after the return。

Additional information Reference atof()。

strtol(Converts a string grow integer)

Related Functions atof,atoi,atoll,strtod,strtoul
Header Files #include
Defined Functions long int strtol(const char * nptr,char **endptr,int base);

Function Description strtol()Nptr string parameter will be converted to long integer parameter according to base。Parameter base ranges from 2 to 36, or 0。Hex mode parameter represents the base employed,The base 10 decimal value 10 is used,If the base is 16 in hexadecimal, etc.。When the base value of 0 is done using 10-ary conversion,But encountered such as’0x 'leading character will do the conversion in hexadecimal。Beginning strtol()It scans the string parameter nptr,Skip over white space characters,Until you meet numbers or the sign began to do the conversion,When it encounters the end of the non-numeric or string(‘/0’)End of conversion,And the results returned。If the parameter is not NULL endptr,The character pointer will encounter substandard conditions and terminated in nptr returned by endptr。

return value Long integer returned after conversion,Otherwise, it returns an error code and ERANGE is stored in errno。

Additional information ERANGE specified conversion string exceeds the legal range。

strtoul(The string into an unsigned long integer)

Related Functions atof,atoi,atoll,strtod,strtol
Header Files #include
Defined Functions unsigned long int strtoul(const char * nptr,char**endptr,int base);

Function Description strtoul()It will be converted into a parameter string nptr unsigned long integer parameter according base。Parameter base ranges from 2 to 36, or 0。Hex mode parameter represents the base employed,The base 10 decimal value 10 is used,When the base 16 is 16 hexadecimal, etc.。When the base value of 0 is done using 10-ary conversion,But encountered such as’0x 'leading character will do the conversion in hexadecimal。Beginning strtoul()It scans the string parameter nptr,Skip string preceding space,Until you meet numbers or the sign began to do the conversion,When it encounters the end of the non-numeric or string(‘/0’)End of conversion,And the results returned。If the parameter is not NULL endptr,The character pointer will encounter substandard conditions and terminated in nptr returned by endptr。

return value Long integer returned after conversion,Otherwise, it returns an error code and ERANGE is stored in errno。

Additional information ERANGE specified conversion string exceeds the legal range。
Reference example strtol()

toascii(Convert integer into a legal ASCII characters)

Related Functions isascii,toupper,tolower
Header Files #include
Defined Functions int toascii(int c)

Function Description toascii()Parameter c will be converted into 7-bit unsigned char value,Eighth will be cleared,That this character will be converted to ASCII characters。

return value The successful conversion of the ASCII character values ​​return。

toupper(The lowercase letters to uppercase)

Related Functions Islf,toupper
Header Files #include
Defined Functions int tolower(int c);

Function Description If the parameter c is uppercase letters corresponding to the return of the lower case。
return value After the return to lowercase conversion,If the value of parameter c to be converted will be returned。

tolower(Convert uppercase letters to lowercase)

Related Functions Islf,tolower
Header Files #include
Defined Functions int toupper(int c);
Function Description If the parameter c is the capital letter lowercase enantiomeric return。
return value After the conversion of capital letters returned,If the value of parameter c to be converted will be returned。

Reference to this articleHere~,Routing just re-publishing content to make it easier to read。

Original article written by Gerber drop-off:R0uter's Blog » Commonly used strings in c-number function

Reproduced Please keep the source and description link:https://www.logcg.com/archives/492.html

By R0uter's Blog

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *