General functions of C language

Source: Internet
Author: User
Tags cos function prototype mathematical functions sin uppercase letter

First, mathematical functions

When a mathematical function is called, the following command line is required to be wrapped in the source file:

#include <math.h>

Function prototype Description

Function

return value

Description

int abs (int x)

To find the absolute value of an integer x

Calculation results

Double fabs (Double x)

Finding the absolute value of a double-precision real X

Calculation results

Double ACOs (Double x)

Calculates the value of Cos-1 (x)

Calculation results

x within the -1~1 range

Double asin (Double x)

Calculates the value of sin-1 (x)

Calculation results

x within the -1~1 range

Double Atan (Double x)

Calculates the value of tan-1 (x)

Calculation results

Double atan2 (Double x)

Calculates the value of the tan-1 (x/y)

Calculation results

Double cos (double x)

Calculate the value of the cos (x)

Calculation results

The units of X are in radians

Double cosh (Double x)

Computes the value of the hyperbolic cosine cosh (x)

Calculation results

Double exp (Double x)

Find the value of ex

Calculation results

Double fabs (Double x)

Finding the absolute value of a double-precision real X

Calculation results

Double floor (Double x)

The maximum integer that is not greater than the double-precision real X

Double Fmod (double x,double y)

Finding the double-precision remainder after X/Y division

Double Frexp (double val,int *exp)

The double Val decomposes the mantissa and the 2-based exponent N, that is, the val=x*2n,n is stored in the variable that the exp refers to

Return number of Bits X

0.5≤x<1

Double log (double x)

Beg ㏑x

Calculation results

X>0

Double log10 (Double x)

Beg log10x

Calculation results

X>0

Double modf (double val,double *ip)

The double Val is decomposed into an integer part and a fractional part, and the integer portion is stored in the variable referred to by the IP.

Returns the number of decimal points

Double pow (double x,double y)

Calculate the value of XY

Calculation results

Double sin (double x)

Calculates the value of sin (x)

Calculation results

The units of X are in radians

Double Sinh (Double x)

Calculates the value of X's hyperbolic sine function sinh (x)

Calculation results

Double sqrt (double x)

Calculate the root of X

Calculation results

X≥0

Double tan (Double x)

Calculate tan (x)

Calculation results

Double Tanh (Double x)

Computes the value of the hyperbolic tangent function of x tanh (x)

Calculation results

Second, character function

When calling the character function, the following command line is required to be wrapped in the source file:

#include <ctype.h>

Function prototype Description

Function

return value

int isalnum (int ch)

Check if CH is a letter or a number

Yes, returns 1; otherwise returns 0

int isalpha (int ch)

Check if CH is a letter

Yes, returns 1; otherwise returns 0

int Iscntrl (int ch)

Check if CH is a control character

Yes, returns 1; otherwise returns 0

int isdigit (int ch)

Check if CH is a number

Yes, returns 1; otherwise returns 0

int isgraph (int ch)

Check if CH is an ASCII value in ox21 to ox7e printable character (that is, does not contain a space character)

Yes, returns 1; otherwise returns 0

int islower (int ch)

Check if CH is a lowercase letter

Yes, returns 1; otherwise returns 0

int isprint (int ch)

Check if CH is a printable character, including whitespace

Yes, returns 1; otherwise returns 0

int ispunct (int ch)

Check if CH is a printable character other than spaces, letters, numbers

Yes, returns 1; otherwise returns 0

int isspace (int ch)

Check if CH is a space, tab, or line break

Yes, returns 1; otherwise returns 0

int isupper (int ch)

Check if CH is an uppercase letter

Yes, returns 1; otherwise returns 0

int isxdigit (int ch)

Check if CH is 16 binary number

Yes, returns 1; otherwise returns 0

int tolower (int ch)

Convert the letters in CH into lowercase letters

Returns the corresponding lowercase letter

int toupper (int ch)

Convert the letters in CH to uppercase

Returns the corresponding uppercase letter

Three, String function

When calling the character function, the following command line is required to be wrapped in the source file:

#include <string.h>

Function prototype Description

Function

return value

Char *strcat (char *s1,char *s2)

S2 string to S1 back

Address referred to by S1

Char *strchr (char *s,int ch)

Find the position of the first occurrence of the character ch in the S-referred string

Returns the address of the found character, no return null found

int strcmp (char *s1,char *s2)

Comparison of strings referred to by S1 and S2

S1<S2, returns a negative number; s1= =s2, returns 0;S1>S2, returns a positive number

Char *strcpy (char *s1,char *s2)

Copy the string that S2 points to the space that S1 points to

Address referred to by S1

unsigned strlen (char *s)

To find the length of the string s

Returns the number of characters in a string (not counting the last ' s ')

Char *strstr (char *s1,char *s2)

In the string S1, find the first occurrence of the string s2

Returns the address of the found string, no return null found

Iv. input and OUTPUT functions

When calling the character function, the following command line is required to be wrapped in the source file:

#include <stdio.h>

Function prototype Description

Function

return value

void clearer (FILE *fp)

Clears all error messages related to the file pointer fp

No

int fclose (FILE *fp)

Closes the file referred to by the FP, releasing the file buffer

Error returns non 0, otherwise returns 0

int feof (FILE *fp)

Check if the file ends

Returns 0 if the end of the file is not returned, otherwise 0

int fgetc (FILE *fp)

Get the next character from the file referred to in the FP

Error returns EOF, otherwise the read character is returned

Char *fgets (char *buf,int N, FILE *FP)

Reads a string of length n-1 from the file referred to by the FP and stores it in the BUF-referred storage area

Returns the address referred to by BUF, or returns null if the file ends or an error occurs

FILE *fopen (char *filename,char *mode)

Open a file named filename in the mode specified by mode

Successful, returns the file pointer (the start address of the file information area), otherwise returns null

int fprintf (FILE *fp, Char *format, args,...)

,... the Args Output to the FP-specified file in the format specified by format

The actual number of characters to output

int FPUTC (char ch, FILE *FP)

Output ch characters to the FP-specified file

The character is returned successfully, or EOF is returned

int fputs (char *str, FILE *FP)

Outputs the string str refers to the file referred to in the FP

A non-negative integer was returned successfully, otherwise 1 (EOF)

int fread (char *pt,unsigned size,unsigned N, FILE *FP)

Reads the length from the FP-referred file size to n data items to a PT-referred file

Number of data items read

int fscanf (FILE *fp, char *format,args,...)

The input data is deposited into the args,... in the format specified by format in the file referred to by the FP. Referred to in-memory

Number of data entered, end of file or error returned 0

int fseek (FILE *fp,long offer,int Base)

Position pointer of the file moved by the FP

The current position is returned successfully, otherwise 0 is not returned

Long Ftell (FILE *FP)

Find the current read and write location of the file referred to by the FP

Read and write location, error return -1l

int fwrite (char *pt,unsigned size,unsigned N, FILE *FP)

Enter the N*size bytes pointed to by PT into the file referred to in the FP

Number of data items to output

int getc (FILE *fp)

Reads a character from a file that is referred to in the FP

Returns the read character, if an error occurs or the end of the file returns EOF

int GetChar (void)

Reading the next character from a standard input device

Returns the read character, if an error occurs or the end of the file returns-1

Char *gets (char *s)

Reads a line of string from a standard device into the storage area referred to by S, replacing the read-in line break with '% '

Returns s, error returns null

int printf (char *format,args,...)

,... the Args Output to a standard output device in the format specified by format

Number of output characters

int PUTC (int ch, FILE *FP)

With FPUTC

With FPUTC

int Putchar (char ch)

Output ch to standard output device

Returns the character of the output, or EOF if an error occurs

Int puts (char *str)

Output the STR string to the standard device and convert '% ' to carriage return newline.

Returns the newline character, in case of an error, returns EOF

int rename (char *oldname,char *newname)

Change the file name referred to Oldname to the name of NewName

Successfully returned 0, error returned-1

void Rewind (FILE *fp)

Place the file position pointer at the beginning of the file

No

int scanf (char *format,args,...)

The input data is deposited into the args from the standard input device in the format specified by format,... Referred to in-memory

The number of data that has been entered

V. Dynamic allocation functions and random functions

When calling the character function, the following command line is required to be wrapped in the source file:

#include <stdlib.h>

Function prototype Description

Function

return value

void *calloc (unsigned n,unsigned size)

Allocates the memory space of n data items, each data item size is a byte

The starting address of the allocated memory unit; If unsuccessful, returns 0

void *free (void *p)

Releasing the memory area referred to by P

No

void *malloc (unsigned size)

Allocate a size byte of storage space

The address of the allocated memory space; If unsuccessful, returns 0

void *realloc (void *p,unsigned size)

Changes the size of the memory area referred to as p to size bytes

The address of the newly allocated memory space; If unsuccessful, returns 0

int rand (void)

Random integers that produce 0~32767

Returns a random integer

void exit (int state)

The program terminates execution, returns the calling procedure, state is 0 normal termination, non 0 non-normal termination

No


Implementation code for C-language standard library functions

C language Common functions Daquan

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.