Common C language library functions (including detailed usage)

A mathematical function

When calling mathematical functions required in the source file package the following command line:

#include <math.h>

Function prototype Description

Features

return value

Explanation

int abs( int x)

Seeking the absolute value of the integer x

Calculation results

 

double fabs(double x)

Double precision absolute value of real number x

Calculation results

 

double acos(double x)

Calcd cos-1 (x) of

Calculation results

x is in the range of -1 to 1

double asin(double x)

Calcd sin-1 (x) of

Calculation results

x is in the range of -1 to 1

double atan(double x)

Calcd tan-1 (x) of

Calculation results

 

double atan2(double x)

Calcd tan-1 (x / y) of

Calculation results

 

double cos(double x)

Calculating cos (x) value

Calculation results

x is in radians

double cosh(double x)

Calculating cosh cosh (x) value

Calculation results

 

double exp(double x)

Evaluation of ex

Calculation results

 

double fabs(double x)

Double precision absolute value of real number x

Calculation results

 

double floor(double x)

Seeking no greater than double the maximum real number x is an integer

 

 

double fmod(double x,double y)

Double the number of required I x / y divisible

 

 

double frexp(double val,int *exp)

Val the double decomposition base 2 and the mantissa exponent n, i.e. val = x * 2n, n is stored in a variable referred to in exp

Returns the number of bits x

0.5≤x<1

 

double log(double x)

Seeking ㏑x

Calculation results

x>0

double log10(double x)

Seeking log10x

Calculation results

x>0

double modf(double val,double *ip)

The double val decomposed into integer and fractional parts, stored in the integer part of a variable referred to in ip

Returns the fractional part

 

double pow(double x,double y)

Calculated value of xy

Calculation results

 

double sin(double x)

Calculate sin (x) value

Calculation results

x is in radians

double sinh(double x)

Hyperbolic sine function sinh (x) calculation of the value of x

Calculation results

 

double sqrt(double x)

Calculate the square root of x

Calculation results

x≥0

double tan(double x)

Calculating tan (x)

Calculation results

 

double tanh(double x)

Calculating x hyperbolic tangent function tanh (x) value

Calculation results

 

Second, the character function

When you call a character function in the source file package requires the following command line:

#include <ctype.h>

Function prototype Description

Features

return value

int isalnum(int ch)

Ch check whether a letter or digit

Yes, returns 1; otherwise it returns 0

int isalpha(int ch)

Check whether the letter ch

Yes, returns 1; otherwise it returns 0

int iscntrl(int ch)

Check whether ch is a control character

Yes, returns 1; otherwise it returns 0

int isdigit(int ch)

Check whether the digital ch

Yes, returns 1; otherwise it returns 0

int isgraph(int ch)

Ch checks whether the value of the ASCII code to ox7e ox21 printable characters (i.e. no space character)

Yes, returns 1; otherwise it returns 0

int islower(int ch)

Check the ch is a lowercase letter

Yes, returns 1; otherwise it returns 0

isprint you (you ch)

Check whether ch to contain spaces, including printable characters

Yes, returns 1; otherwise it returns 0

int ispunct(int ch)

In addition to checking whether ch spaces, letters, numbers, printable characters

Yes, returns 1; otherwise it returns 0

int isspace(int ch)

Check whether ch spaces, tabs, or line breaks

Yes, returns 1; otherwise it returns 0

int isupper(int ch)

Check the ch is an uppercase letter

Yes, returns 1; otherwise it returns 0

int isxdigit(int ch)

Ch check whether the hexadecimal

Yes, returns 1; otherwise it returns 0

int tolower(int ch)

Ch converted into lowercase letters

Corresponding to the returned lowercase

int toupper(int ch)

The letters converted to uppercase letters ch

Returns uppercase corresponding

Third, String Functions

When you call a character function in the source file package requires the following command line:

#include <string.h>

Function prototype Description

Features

return value

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

String s1 s2 to the rear

the address indicated by s1

char *strchr(char *s,int ch)

Referred to in s string to find the first character position appears ch

The return address of the character found, can not find returns NULL

int strcmp(char *s1,char *s2)

S1 and s2 referred to compare strings

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

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

把s2指向的串复制到s1指向的空间

s1 所指地址

unsigned strlen(char *s)

求字符串s的长度

返回串中字符(不计最后的'\0')个数

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

在s1所指字符串中,找出字符串s2第一次出现的位置

返回找到的字符串的地址,找不到返回NULL

四、输入输出函数

调用字符函数时,要求在源文件中包下以下命令行:

#include <stdio.h>

函数原型说明

功能

返回值

void clearer(FILE *fp)

清除与文件指针fp有关的所有出错信息

int fclose(FILE *fp)

关闭fp所指的文件,释放文件缓冲区

出错返回非0,否则返回0

int feof (FILE *fp)

检查文件是否结束

遇文件结束返回非0,否则返回0

int fgetc (FILE *fp)

从fp所指的文件中取得下一个字符

出错返回EOF,否则返回所读字符

char *fgets(char *buf,int n, FILE *fp)

从fp所指的文件中读取一个长度为n-1的字符串,将其存入buf所指存储区

返回buf所指地址,若遇文件结束或出错返回NULL

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

以mode指定的方式打开名为filename的文件

成功,返回文件指针(文件信息区的起始地址),否则返回NULL

int fprintf(FILE *fp, char *format, args,…)

把args,…的值以format指定的格式输出到fp指定的文件中

实际输出的字符数

int fputc(char ch, FILE *fp)

把ch中字符输出到fp指定的文件中

成功返回该字符,否则返回EOF

int fputs(char *str, FILE *fp)

把str所指字符串输出到fp所指文件

成功返回非负整数,否则返回-1(EOF)

int fread(char *pt,unsigned size,unsigned n, FILE *fp)

从fp所指文件中读取长度size为n个数据项存到pt所指文件

读取的数据项个数

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

从fp所指的文件中按format指定的格式把输入数据存入到args,…所指的内存中

已输入的数据个数,遇文件结束或出错返回0

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

移动fp所指文件的位置指针

成功返回当前位置,否则返回非0

long ftell (FILE *fp)

求出fp所指文件当前的读写位置

读写位置,出错返回 -1L

int fwrite(char *pt,unsigned size,unsigned n, FILE *fp)

把pt所指向的n*size个字节输入到fp所指文件

输出的数据项个数

int getc (FILE *fp)

从fp所指文件中读取一个字符

返回所读字符,若出错或文件结束返回EOF

int getchar(void)

从标准输入设备读取下一个字符

返回所读字符,若出错或文件结束返回-1

char *gets(char *s)

从标准设备读取一行字符串放入s所指存储区,用’\0’替换读入的换行符

返回s,出错返回NULL

int printf(char *format,args,…)

把args,…的值以format指定的格式输出到标准输出设备

输出字符的个数

int putc (int ch, FILE *fp)

同fputc

同fputc

int putchar(char ch)

把ch输出到标准输出设备

返回输出的字符,若出错则返回EOF

int puts(char *str)

把str所指字符串输出到标准设备,将’\0’转成回车换行符

返回换行符,若出错,返回EOF

int rename(char *oldname,char *newname)

把oldname所指文件名改为newname所指文件名

成功返回0,出错返回-1

void rewind(FILE *fp)

将文件位置指针置于文件开头

int scanf(char *format,args,…)

从标准输入设备按format指定的格式把输入数据存入到args,…所指的内存中

已输入的数据的个数

五、动态分配函数和随机函数

调用字符函数时,要求在源文件中包下以下命令行:

#include <stdlib.h>

函数原型说明

功能

返回值

void *calloc(unsigned n,unsigned size)

分配n个数据项的内存空间,每个数据项的大小为size个字节

分配内存单元的起始地址;如不成功,返回0

void *free(void *p)

释放p所指的内存区

void *malloc(unsigned size)

分配size个字节的存储空间

分配内存空间的地址;如不成功,返回0

void *realloc(void *p,unsigned size)

把p所指内存区的大小改为size个字节

新分配内存空间的地址;如不成功,返回0

int rand(void)

产生0~32767的随机整数

返回一个随机整数

void exit(int state)

程序终止执行,返回调用过程,state为0正常终止,非0非正常终止

发布了407 篇原创文章 · 获赞 150 · 访问量 38万+

Guess you like

Origin blog.csdn.net/ds1130071727/article/details/102784866