Summarizes the common library functions in C language in Linux-String Conversion, character testing, and memory control.

Source: Internet
Author: User
Tags float number natural logarithm

Summarizes the common library functions in C language in Linux-String Conversion, character testing, and memory control.

When there is no IDE, it is necessary to remember the name, parameters, basic usage, and precautions of some common library functions.

Refer to the Linux_C_HS.chm directory. I roughly divide common functions into the following categories:

  • 1. Memory and string control and operations
  • 2. String Conversion
  • 3. Character Testing
  • 4. File Operations
  • 5. time and date
  • 6. Common mathematical functions
  • 7. File Content operations
  • 8. File Permission Control
  • 9. process operations
  • 10. Thread operations
  • 11. Socket operations
  • 12. Signal Processing
  • 13. data structures and algorithms

 

 

  • String Conversion Classification
* Function name Usage Notes
*
* 1. Double atof (const char * nptr); convert a string to a double
*
* 2. Int atoi (const char * nptr); convert a string to an integer UP
*
* 3. Long long atoll (const char * nptr); UP UP
*
* 4. Float strtof (const char * nptr, char ** endptr); UP If endptr is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by
                                                                                    endptr.
*
* 5. Int toascii (int c); convert character to ASCII The value returned is that of the converted character.
*
* 6. Int toupper (int c); convert letter to upper or lower case The value returned is that of the converted letter, or c if the conversion was not possible.
*
* 7. Int tolower (int c); UP UP
*
* 8. Char * gcvt (double number, size_t ndigit, char * buf); convert a floating-point returns the address of the string pointed to by buf.
  • String Test Category
* Function name Usage Notes
*
* 1. Int isalnum (int c); whether it is English or number. Returns 1 correctly, 0 if error.
*
* 2. Int isalpha (int c); whether it is English alphabet UP
*
* 3. Int isascii (int c); whether it is ASCII code UP
*
* 4. Int isblank (int c); a space or a tab NT
*
* 5. Int isgraph (int c); printable characters, excluding spaces NT
*
* 6. Int iscntrl (int c); NT NT
*
* 7. Int isdigit (int c); NT NT
*
* 8. Int isprint (int c); printable characters, including spaces NT
*
* 9. Int ispunct (int c); punctuation or special character NT
*
* 10. Int isspace (int c); space, form-feed ('\ f'), NT
                                                newline ('\ n'), carriage
                                                return ('\ r'), horizontal tab
                                                ('\ t'), and vertical tab ('\ v').
*
* 11. Int isupper (int c); NT NT
*
* 12. Int isxdigit (int c); Hex NT
*
  • Memory control class Induction
* Function name Usage Notes
*
* 1. Void * malloc (size_t size); NT does not initialize by default
*
* 2. Void * calloc (size_t nmemb, size_t size); Apply for space of size nmemb. The default initial value is 0
*
* 3. Void * realloc (void * ptr, size_t size); extended memory area The newly expanded part is not initialized by default
*
* 4. Void free (void * ptr); release memory area NT 

 

As shown aboveString Conversion, string testing, and memory controlSummary.

 


Provides some library functions commonly used in the C language, and describes its functions and header files.

Character Processing functions
This category function is used to process a single character, including the character category test and case-insensitive conversion of characters.

Header file ctype. h

Function list <>
Function category function usage
Character test whether letters and numbers are isalnum
Isalpha or not
Whether to control the iscntrl character
Isdigit
Whether to display characters (except spaces) isgraph
Whether to display characters (including spaces) isprint
Ispunct, a printable character that is neither a space nor a letter or number
Space or not isspace
Whether to use uppercase letters: isupper
Whether the hexadecimal number (0-9, A-F) character isxdigit
The case-sensitive conversion function converts uppercase letters to toupper.
Convert to lower case tolower

Regionalization
Functions of this category are used to handle different languages in different countries.

Header file local. h

Function list
Function category function usage
Setlocale
The format of the Number Format Convention to query the country's currency, date, time format conversion localeconv

Mathematical functions
This category provides various mathematical computing functions. It must be noted that the data format in ansi c does not conform to the IEEE754 standard, while some C language compilers follow the IEEE754 standard (such as frinklin C51)

Header file math. h

Function list
Function category function usage
Error Condition processing definition field error (the input parameter value of the function is not within the specified range)
Value Range Error (the return value of the function is not within the specified range)
Trigonometric inverse cosine acos
Asin
Switch atan
Arc tangent 2 atan2
Cosine cos
Sine sin
Tangent tan
Hyperbolic function hyperbolic cosine cosh
Hyperbolic sinh
Hyperbolic tangent tanh
Exponential and logarithm Exponential Function exp
Exponential decomposition function frexp
Product exponent function fdexp
Natural logarithm log
Base-10 logarithm log10
Floating Point decomposition function modf
Power Function pow
Square Root function sqrt
Integer truncation. the lower limit of the absolute value and the remainder function is close to the integer ceil.
Absolute Value fabs
The upper limit is close to the integer floor.
Evaluate the remainder fmod

This category function is used to directly jump code between different base functions. Header file setjmp. h io. h

Function list
Function category function usage
Save the call environment setjmp
Restore the call environment longjmp

Signal Processing
This classification function is used to handle exceptions during program execution.

Header file signal. h

Function list
Function category function usage
Signal processing function signal
Send signal raise

Variable Parameter Processing
This class of functions is used to implement variable number of parameters such as printf and scanf.

Header file stdarg. h

Function list
Function category function usage
Variable Parameter access macro variable parameter start macro va_start
Variable Parameter end macro va_end
Variable Parameter access macro access next variable parameter macro va_arg

Input and Output Functions
This category is used to process various input and output devices, including files and the console. Various functions are implemented in a "stream" manner.

Header file stdio. h

Function list
Function category function usage
File Operations
Delete file remove
Rename
Generate temporary file name tmpfile
Get the temporary file path tmpnam
File Access close file fclose
Refresh the buffer fflush
Open File fopen
Connect existing stream pointers and new files to freope ...... the remaining full text>

C language library functions include functions that convert numbers to strings

1. itoa

Function: converts an integer to a string.

Usage: char * itoa (int value, char * string, int radix );

Description: itoa is the abbreviation of the English integer to array (converting the int integer into a string and saving the value in the array string.

Parameters:

Value: the integer to be converted.

Radix: indicates the base number, that is, the value is first converted to the base number of radix. The value range is between 2 and 36. For example, 10 indicates 10 hexadecimal and 16 indicates hexadecimal.

* String: Save the converted string.

Return Value:

Char *: indicates the generated string, which is the same as * string.

Note: The header file of this function is "stdlib. h"

2. ltoa

Function: converts a long integer to a string.

Usage: char * ltoa (long value, char * string, int radix );

Description: itoa is the abbreviation of long integer to array (converting the long integer of long int into a string and saving the value in the array string.

Parameters:

Value: the number of long integers to be converted.

Radix: indicates the base number, that is, the value is first converted to the base number of radix. The value range is between 2 and 36. For example, 10 indicates 10 hexadecimal and 16 indicates hexadecimal.

* String: Save the converted string.

Return Value:

Char *: indicates the generated string, which is the same as * string.

Note: The header file of this function is "stdlib. h"

3. ultoa

Function: converts an unsigned long integer to a string.

Usage: char * ultoa (unsigned long value, char * string, int radix );

Description: itoa is the abbreviation of unsigned long integer to array (converting unsigned long int unsigned long integer to a string and saving the value in the array string.

Parameters:

Value: the number of unsigned long integers to be converted.

Radix: indicates the base number, that is, the value is first converted to the base number of radix. The value range is between 2 and 36. For example, 10 indicates 10 hexadecimal and 16 indicates hexadecimal.

* String: Save the converted string.

Return Value:

Char *: indicates the generated string, which is the same as * string.

Note: The header file of this function is "stdlib. h"

4. gcvt

Function: converts the float number to a string and returns the rounded value.

Usage: char * gcvt (double value, int ndigit, char * buf );

Explanation: 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.

Parameters:

Value: The floating point number to be converted.

Ndigit: The number of valid digits stored.

* Buf: The storage location of the result.

Return Value:

Char *: indicates the generated string, which is the same as * buf.

Note: The header file of this function is "stdlib. h"

5. ecvt

Function: Convert the Double Precision Floating Point type to a string, and convert it to the rest of the text...>

Related Article

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.