Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Find all the simple functions in C language!
Find all the simple functions in C language!
Library function is not a part of C language, it is a set of programs compiled by the compiler according to the needs of ordinary users and provided to users. Each C compiler system provides multiple library functions, and the number, names and functions of library functions provided by different compiler systems are not exactly the same. ANSIC standard puts forward many suggested standard library functions. It contains the library functions provided by most C compiler systems at present, but some of them are not implemented by some C compiler systems. Considering universality, this book lists some common library functions provided by Turbo C 2.0.

Due to the variety and quantity of Turbo C library functions (for example, there are screen and graphic functions, time and date functions, functions related to this system, etc.). , and each function contains a variety of functions), due to space constraints, this appendix can not introduce all, only from the perspective of teaching needs to list the most basic. Readers may need to use more functions when compiling C programs. Please refer to the relevant Turbo C library function manual.

(1) mathematical function

When using mathematical functions, you should use the commands in the source file:

# contains "math.h"

Function name, function and function return value of parameter type.

acos double acos(x)

Double x calculates the value of cos- 1(x).

- 1 & lt; = x<= 1 calculation result

Asin Double Asin (X)

Double x calculates the value of sin- 1(x).

- 1 & lt; = x<= 1 calculation result

Atan double atam (x)

Double x calculates the value of tan- 1(x).

atan2 double atan2(x,y)

Double x, y calculates the value of tan- 1(x/y).

cos double cos(x)

Double x calculates the value of cos(x)

The unit of x is the radian calculation result.

Double Coase (x)

Double x calculates the hyperbolic cosine of x.

exp double exp(x)

Double x found the value calculation result of e X.

Double wafer factory (x)

Calculation result of double x absolute value

Double floor

Double x finds the largest integer not greater than x and the double-precision real number of the integer.

fmoddouble fmod(x,y)

Double x, y finds the remainder of x/y and returns the double-precision real number of the remainder.

frexp double frexp(val,eptr)

Double val

Int *eptr decomposes the double-precision number val into a digital part (mantissa) and a base-2 exponent, that is, Val = x * 2n, where n is stored in the digital part X of the variable pointed by eptr.

0.5 & lt= x & lt 1

Logarithm-logarithm (x)

Double x finds logex, which is the calculation result of lnx.

Logarithm 10 logarithm 10(x)

Double x finds the calculation result of log 10x.

modf double modf(val,iptr)

Double val

Int *iptr decomposes the double-precision number val into a number part and a decimal part, and stores the integer part of the decimal part of val in the variable pointed by ptr.

pow double pow(x,y)

Calculation results of finding xy value by double x and y

sin double sin(x)

Double x finds the value of sin(x)

The unit of x is the radian calculation result.

sinh double sinh(x)

Double x calculates the value of sinh(x), a hyperbolic sine function of x.

sqrt double sqrt(x)

Double x calculation √ x, x ≧ 0 calculation results

Tan (x)

Double x calculates the value of tan(x)

The unit of x is the radian calculation result.

Hyperbolic tangent (x)

Double x calculates the value of the hyperbolic tangent function tanh(x) of x.

-

(2) Personality function

When using character functions, you should use the commands in the source file:

# contains "ctype.h"

Function name function and parameter type function return value

Isalem

Intch checks whether ch is a letter or a number and returns1; Otherwise, 0 is returned.

Aysel method

Intch checks whether ch is a letter and returns1; Otherwise, 0 is returned.

isc ntrint isc ntrl(ch)

Intch checks whether ch is a control character (its ASC code is between 0 and 0xlF) and returns1; Otherwise, 0 is returned.

isdigitint isdigit(ch)

Intch checks whether ch is a number and returns1; Otherwise, 0 is returned.

is graphint is graph(ch)

Intch checks whether ch is a printable character (its ASC code is between 0x2 1 and 0x7e). If CH is a printable character without spaces, it returns1; Otherwise, 0 is returned.

is lowerint is lower(ch)

Intch checks whether ch is lowercase.

(a ~ z) is the small letter that returns 1; Otherwise, 0 is returned.

isprintint isprint(ch)

Intch checks whether ch is a printable character (its ASC code is between 0x2 1 and 0x7e). If CH is a printable character without spaces, it returns1; Otherwise, 0 is returned.

ispuncint ispunct(ch)

Intch checks whether ch is a punctuation character (excluding spaces), that is, all printable characters except letters, numbers and spaces are punctuation, and returns1; Otherwise, 0 is returned.

isspace int is space(ch)

Intch checks whether ch is a space, a tab or a line break, and returns1; Otherwise, 0 is returned.

issupprint is alsupper(ch)

Intch checks whether ch is capitalized.

(a ~ z) is a capital letter and returns1; Otherwise, 0 is returned.

isxdigitint isxdigital(ch)

Intch checks whether ch is a hexadecimal number of 16.

(i.e. 0 ~ 9, or A to F, A to F) Yes, return1; Otherwise, 0 is returned.

to lower int to lower(ch)

Intch converts ch characters into lowercase letters and returns lowercase letters corresponding to ch.

Tupperware tupperware

Intch converts ch characters into capital letters and returns the capital letters corresponding to ch.

-

(3) String function

When using a function in a string, you should use the command in the source file:

# contains "string.h"

Function name function and parameter type function return value

memchrvoid mem chr(buf,ch,count)

void * bufcharch

Unsigned integer count; Searching the first occurrence position of the character ch in the first counting character of buf, and returning a position pointer pointing to the first occurrence position of ch in buf; If ch is not found, NULL is returned.

memcmpint memcmp(buf 1,buf2,count)

void *buf 1,* buf2

Unsigned integer count; The first count character buf 1 < Buf2 is negative.

Buff1= buf2, returns 0.

buf 1 & gt; Buf2 is a positive number.

Memcpyvoid * memcpy (to, from, count)

void *to,* from

Unsigned integer count; Copy the first count characters in the array pointed by from to the array pointed by to. Arrays pointed by From and to are not allowed to overlap and the pointed pointers are returned to.

Memovevoid * memove (to, from, count)

void *to,* from

Unsigned integer count; Copy the first count characters in the array pointed by from to the array pointed by to. Arrays pointed by From and to are not allowed to overlap and the pointed pointers are returned to.

memset void * memset(buf,ch,count)

void * bufchar ch

Unsigned integer count; Copy the character ch into the first count characters of the array pointed by buf. Return to buf

strcatchar * strcat(str 1,str2)

Char *str 1, * str2 concatenates the character str2 after str 1, cancels the last string terminator `\ 0` of str 1, and returns str 1.

strchrchar * strchr(str 1,ch)

char * str

Int ch finds the position where the character ch first appears in the string pointed by str, and returns a pointer to that position. If it cannot be found, it should return NULL.

strcmp int * strcmp(str 1,str2)

Char *str 1, * str2 compare strings str 1 and str2str 1

Str 1=str2, returns 0.

str 1 & gt; Str2 is a positive number.

strcpychar * strcpy(strr 1,str2)

Char *str 1, * str2 copies the string pointed by str2 to str 1 and returns str 1.

Unsigned integer

Char * str counts the number of characters in the string str (excluding the terminator `\ 0`) and returns the number of characters.

Strncat char * strncat (str1,str2, counting)

char *str 1,* str2

Unsigned integer count; Concatenates at most count strings in the string pointed by the string str2 into the string str 1, and returns str 1 ending in null.

Strncmpit strncmp(str 1, str2, counting)

char *str 1,* str2

Unsigned integer count; Compare the first counting character str 1 at most, and str2 < Str2 is negative.

Str 1=str2, returns 0.

str 1 & gt; Str2 is a positive number.

Strncpy char * strncpy (str1,str2, counting)

char *str 1,* str2

Unsigned integer count; Copy the first count characters in the string pointed by str2 to str 1 to return str 1.

strnsetvoid * setn set(buf,ch,count)

char * bufchar ch

Unsigned integer count; Copy the character ch into the first count characters of the array pointed by buf. Return to buf

strstevoid * setn set(buf,ch)

Void * bufCHar ch changes all characters in the string pointed by buf to character ch to return buf.

str strchar * str str(str 1,str2)

Char *str 1, * str2 finds the position where the string pointed by str2 first appears in the string pointed by str 1, and returns the address where the string pointed by str2 first appears. Otherwise, NULL is returned.

-

(4) Input and output functions

When using input-output functions, you should use the commands in the source file:

# contains "stdio.h"

Function name function and parameter type function return value

Clearerrvoid cleaner (fp)

FILE *fp Clear File Pointer Error Indicator None

Close. Close.

Intfp closed file (non-ANSI standard) closed successfully and returned 0; Otherwise, it returns-1

Create Create (file name, schema)

Char * file name;

Intmode creates a document in the way specified by mode. (Non-ANSI standard) successfully returned a positive number.

Otherwise, return-1.

eof int eof(FP)

Intfp judges whether the file pointed by fp ends or not, and returns 1.

Otherwise, 0 is returned.

fcloseint fclose(FP)

FILE *fp closes the file pointed by fp, and it returns 0 if the file buffer is closed successfully, otherwise it returns non-0.

Fiofente

File * FP checks whether the file ends. If the file ends, it returns non-0, otherwise it returns 0.

ferrorint ferror

FILE *fp tests whether the file pointed by fp has errors, and returns 0 if there are no errors;

Otherwise, a non-zero value is returned.

fflushint fflush

FILE *fp saves all the control information and data of the file pointed by fp, and returns 0 correctly;

Otherwise, a non-zero value is returned.

fgetschar * fgets(buf,n,FP)char * buf; int n;

FILE *fp reads a string with the length of (n- 1) from the file pointed by fp and stores it in the space return address BUF with the initial address buf; Return EOF when the file ends or there is an error.

fgetcint

FILE *fp takes the next character from the file pointed by fp and returns the obtained character; Error returned to EOF

FopenFILE * fopen (file name, mode)

Char *filename, * mode If the file named filename is successfully opened in the manner specified by mode, a file pointer will be returned; Otherwise, 0 is returned.

fprintfint fprintf(FP,format,args,…)

FILE * fpChar *format When the value of args is output to the file indicated by fp in the format specified by format, the number of characters actually output.

fputcint fputc(ch,fp)

Char chFILE *fp outputs the character ch to the file pointed by fp, and returns the character if successful; Error returned to EOF

fputsint fputs(str,fp)

Character string; FILE *fp outputs the string specified by str to the file indicated by fp, and returns 0 if successful; Error returned to EOF

fread int fread(pt,size,n,FP)char * pt; Unsigned size, n; FILE *fp reads n data items of size from the file specified by fp, stores them in the memory area pointed by pt, and returns the number of data items read, and returns 0 if the file ends or has errors.

fscanfint fscanf(FP,format,args,…)

FILE * fpChar *format sends the data read from the file specified by fp to the memory variable pointed by args according to the given format (args is a pointer) to input the number of data.

fseek int fseek(FP,offset,base)

FILE * fp long offset; Intbase moves the position pointer of the file specified by fp to the position indicated by base as the benchmark, and offset as the displacement to return to the current position; Otherwise, return-1.

siellFILE * fp

long ftell(FP); Returns the read-write location in the file specified by fp; Otherwise, 0 is returned.

fwriteint fwrite(ptr,size,n,FP)char * ptr; Unsigned size, n; FILE *fp outputs the n*size bytes pointed by ptr to the file pointed by fp, and writes the number of data items into fp file.

getc int getc(FP)

FILE * fp returns the read character from the next character read in the file pointed by fp; If the file is wrong or ends, return to EOF.

GetCharint getChat () reads the next character return character from the standard input device; If the file is wrong or ends, return-1.

gets char * gets(str)

Char *str reads the string from the standard input device and stores it in the array pointed by str, and returns STR successfully, otherwise returns NULL.

Openint open (file name, mode) char * file name;

Intmode opens an existing file named filename in the way specified by mode.

(Non-ANSI standard) Returns the file number (positive number); If opening fails, return-1.

Printfint printf (format, parameters,

…)

Char *format outputs the pointer of the output list args to the output characters of the standard equipment under the control of the character string specified by format; If an error occurs, a negative number is returned.

PRT cint prtc(ch,fp)

Int chFILE * fp outputs the character ch to the fp value file and outputs the character ch; If there is an error, return EOF.

putchar int putchar(ch)

Char ch outputs the character ch to the fp standard output device and returns the newline character; If it fails, return to EOF.

Puts input puts(str)

Char * str outputs the string pointed by STR to the standard output device; Convert' \0' to a carriage return line and return a newline character; If it fails, return to EOF.

putwint putw(w,fp)

int I;

FILE * fp writes an integer I (that is, a word) to the file pointed by fp.

(Non-ANSI standard) Returns the read character; If the file is wrong or ends, return to EOF.

readint read(FD,buf,count)int FD; char * buf

Unsigned integer count; Read count bytes from the file specified by the file number fp to the buffer known by buf (non-ANSI standard) and return the actual number of bytes read. Returns 0 if the file ends, or-1 if there is an error.

Remove int remove (fname)

Char * fname successfully returned 0 when deleting the file named fname; Error returned-1

Rename and remove (oname, nname)

Char *oname, * nname changed the file name pointed by oname to the file name pointed by nname and successfully returned 0; Error returned-1

Rewind to avoid rewinding

FILE * fp puts the file pointer specified by fp at the file header, and clears the end of file flag and error flag None.

Scanfint scanf (format, parameters,

…)

Char *format inputs data from the standard input device to the unit indicated by args according to the format specified by the format string indicated by Format. Args is the number of data read by the pointer and allocated to args. If the file ends, return to EOF;; If there is an error, 0 is returned.

write int write(FD,buf,count)int FD; char * buf

Unsigned counting; Output count characters from the buffer indicated by buf to the file indicated by fd (non-ANSI standard) and return the actual number of bytes written. If there is an error, return-1.

-

(5) Dynamic storage allocation function

When using the dynamic storage allocation function, you should use the command in the source file:

# contains "stdlib.h"

Function name function and parameter type function return value

Calllocvoid * calloc(n, size)

Unsigned n;

Unsigned size; The continuous memory space of n data items is allocated, and the size of each data item is the size of the starting address of the allocated memory unit. If it is not successful, return 0.

Free, free.

void * p; Release the memory area pointed by p.

Mallocvoid * malloc (size)

Unsigned size; The address of the memory area allocated by the memory area allocated with size bytes. If there is not enough memory, it returns 0.

realloc void * reallod(p,size)

void * p;

Unsigned size; Change the size of the memory area allocated by p to size. The size can be larger or smaller than the original allocated space, and a pointer to the memory area is returned. If redistribution fails, NULL is returned.

-

(6) Other functions

"Other functions" is the standard library function of C language, so it is listed separately because it is not convenient to be classified into a certain category. When using this write function, you should use the command in the source file:

# contains "stdlib.h"

Function name function and parameter type function return value

Absint abs (digital)

Intnum calculates the absolute value of integer num and returns the calculation result.

Atof double atof(str)

Char *str converts the string pointed by str into a double value and returns the result of double precision calculation.

A Toit Atoy

Char *str converts the string pointed by str into an int value and returns the conversion result.

Atolong atoll

Char *str converts the string pointed by str into a long integer value and returns the conversion result.

Exitvoid exit (status)

Int status; Abort the program Returns the value of status to the called procedure None.

itoa char * itoa(n,str,radix)

Int n, radix;

Char *str converts the value of integer n into an equivalent string according to radix, stores the result in the string pointed by str, and returns a pointer to STR.

Laboratory Dragon Laboratory (quantity)

Longnum calculates the absolute value of c integer num and returns the calculation result.

ltoachar * ltoa(n,str,radix)

long int n; Int cardinal number;

Char * str converts the value of long integer n into an equivalent string according to the radix system, stores the result in the string pointed by str, and returns a pointer to STR.

Randint rand () generates a pseudo-random number between 0 and RAND_MAX. RAND_MAX defines in the header file to return a pseudo-random (integer) number.

random

Int num generates random numbers between 0 and num. Returns a random (integer) number

Rand _ omizevoid randomize () () initializes a random function, which contains the header file time.h

Strtoddouble strtod (start, end)

char * start

Char **end converts the numeric string pointed by start into a double until a character that cannot be converted into a floating point appears, and the remaining string characters are given to the pointer end.

* hug _ val is the conversion result of overflow flag value of mathematical function defined by turboC in the header file math.H If it is conversion, it returns 0. If there is a conversion error, return a huge value of overflow or a huge value of underflow.

StrtolLong int strtol (start, end, radix)

char * start

char * * end

Int cardinal number; Convert the numeric string pointed by start to long until a character that cannot be converted into an integer appears, and the rest of the string characters are ended for the pointer.

When converting, the radix of the number changes from the radix.

Of course.

*LONG_MAX is the maximum representation of the Long type defined by turboC in the header file limits.h, and returns the conversion result. If it is a conversion, it returns 0. If there is an error in the conversion, return LONG_MAX for overflow and -LONG_MAX for underflow.

System system

Char * str passes the string pointed by STR as a command to the command processor of DOS, and returns the exit status of the executed command.