_2 standard library functions

math.h

Macro library

Macros Explanation
HUGE_VAL When the result of the function can not be represented as floating point numbers. If it is because the magnitude of the result is too large to be represented, the function sets errno to ERANGE to represent the range of error, and a return by the macro HUGE_VAL or its negation - a certain large value name (HUGE_VAL) of. If the result of too small an amplitude, a zero value is returned. In this case, error may be set to ERANGE, there may not be set to ERANGE.

Trigonometric functions

function Explanation
double sin(double angle) Returns the sine of the angle in radians angle.
double cos(double angle) Returns the cosine of the angle in radians angle.
double tan(double angle) Returns the tangent of the angle in radians angle.
double asin(double value) Return value in radians the arcsine.
double acos(double value) Returns the value of the arc cosine in radians.
double atan(double value) Return value in radians the arctangent.
double atan2(double y, double x) Back in radians y / x arctangent. Symbol values ​​x and y determine the correct quadrant.

note:

  • sin, cos, tanThe angle of the input parameters are in radians.
  • asin, acosThe parameter if it is not -1~1a domain error between, appeared.
  • asin, atan: The return value of the range -pi/2~pi/2in radians between.
  • acosThe return value are: -pi~piarc between.

Hyperbolic functions

function Explanation
double sinh(double angle) Returns the hyperbolic sine of the angle in radians angle.
double cosh(double angle) Returns the hyperbolic cosine of an angle in radians angle.
double tanh(double angle) Returns the hyperbolic tangent of an angle in radians angle.

Logarithmic and exponential functions

function Explanation
double exp(double x) Returns the value e raised to the power x.
double log(double x) X returns the natural logarithm (base e of the logarithm).
double log10(double x) Returns x common logarithm (base 10 logarithm).

Floating point representation

function Explanation
double frexp(double x, int *exponent) The floating-point number into a mantissa and an exponent x decomposition. The return value is the mantissa, and the exponent is stored in the index. The resultant value is x = mantissa * 2 ^ exponent, mantissa is the return value of the function.
double ldexp(double x, int exponent) Returns the x multiplied by 2 to the power of the exponent.
double modf(double x, double *integer) The return value is the fractional part (portion after the decimal point), and sets the integer to integer part.

power

function Explanation
double pow(double x, double y) Return x to the power y.
double sqrt(double x) Returns the square root of x.

The real, the top number, the absolute value of the remainder

function Explanation
double ceil(double x) It returns an integer greater than or equal to a minimum value of x.
double floor(double x) Returns the largest integer value less than or equal to x.
double fabs(double x) Returns the absolute value of x.
double fmod(double x, double y) Returns the remainder of x divided by y.

time.h

Macro library

Macros Explanation
NULL A null pointer value is constant.
CLOCKS_PER_SEC It indicates the number of clocks per second processor.

Library variable

variable Explanation
size_t Is an unsigned integer type, it is the result of sizeof keyword.
clock_t Is a type of memory for processor time.
time_t It is a type suitable for storing calendar time.
struct tm It is a structure to hold the time and date.

tmStructure is defined as follows:

struct tm {
   int tm_sec;         /* 秒,范围从 0 到 59        */
   int tm_min;         /* 分,范围从 0 到 59        */
   int tm_hour;        /* 小时,范围从 0 到 23        */
   int tm_mday;        /* 一月中的第几天,范围从 1 到 31    */
   int tm_mon;         /* 月,范围从 0 到 11        */
   int tm_year;        /* 自 1900 年起的年数        */
   int tm_wday;        /* 一周中的第几天,范围从 0 到 6    */
   int tm_yday;        /* 一年中的第几天,范围从 0 到 365    */
   int tm_isdst;       /* 夏令时                */
};

Processor time

function Explanation
clock_t clock(void) 返回程序执行起(一般为程序的开头),处理器时钟所使用的时间。返回值通常是处理器时钟滴答的次数,为了把这个数值转换成秒,需要除以CLOCKS_PER_SEC。

当天时间

函数 说明
time_t time(time_t *timer) 计算当前日历时间,并把它编码成 time_t 格式。

说明:

  • 如果参数是非NULL值,时间值也将通过这个这个指针进行存储。
  • 如果机器无法提供当前的日期和时间,或者时间值太大,无法使用time_t变量表示,函数返回-1
  • 在MS-DOS和UNIX系统中,时刻开始流失的时刻是1970年1月1日00:00:00 。

日期和时间转换

函数 说明
char ctime(const time_t timer) 返回一个表示当地时间的字符串,当地时间是基于参数 timer。
double difftime(time_t time1, time_t time2) 返回 time1 和 time2 之间相差的秒数 (time1-time2)。
struct tm gmtime(const time_t timer) timer 的值被分解为 tm 结构,并用协调世界时(UTC)也被称为格林尼治标准时间(GMT)表示。
struct tm localtime(const time_t timer) timer 的值被分解为 tm 结构,并用本地时区表示。
char asctime(const struct tm timeptr) 返回一个指向字符串的指针,它代表了结构 timeptr 的日期和时间。
size_t strftime(char str, size_t maxsize, const char format, const struct tm *timeptr) 根据 format 中定义的格式化规则,格式化结构 timeptr 表示的时间,并把它存储在 str 中。
time_t mktime(struct tm *timeptr) 把 timeptr 所指向的结构转换为一个依据本地时区的 time_t 值。

注意:

  • strftime格式化代码:
代码 说明
%% 百分号
%a 星期几的简写
%A 星期几的全称
%b 月份的简写
%B 月份的全称
%c 日期和时间
%d 一个月的第几天(01-31)
%H 24小时制的小时(00-23)
%I 12小时制的小时(00-12)
%J 一年的第几天
%m 月数(01-12)
%M 分钟(00-59)
%p 本地的AM或PM的等价显示
%S 秒(00-59)
%U 一年的第几周,把星期日做为第一天(值从0到53)
%w 一星期的第几天,星期日为第0天
%W 一年的地基星期(值从0到53),星期一为第一天
%x 使用本地的日期格式
%X 使用本地的时间格式
%y 当前世纪的年份(00-99)
%Y 年份的全写形式
%Z 时区名称,如果不能得到时区名称则返回空字符。

assert.h

说明
void assert(int expression) 这实际上是一个宏,不是一个函数,可用于在 C 程序中添加诊断。

说明:

  • 如果宏对表达式测试的结果为假,它就向标准错误打印一条诊断信息并终止程序。
  • 当程序被完整测试完毕之后,可以在编译时通过定义NDEBUG消除所有的断言。当NDEBUG被定义后,预处理器将丢弃所有的断言,而不必在程序中把所有的断言实际删除。

ctype.h

函数 说明
int isalnum(int c) 该函数检查所传的字符是否是字母和数字。
int isalpha(int c) 该函数检查所传的字符是否是字母。
int iscntrl(int c) 该函数检查所传的字符是否是控制字符。
int isdigit(int c) 该函数检查所传的字符是否是十进制数字。
int isgraph(int c) 该函数检查所传的字符是否有图形表示法。
int islower(int c) 该函数检查所传的字符是否是小写字母。
int isprint(int c) 该函数检查所传的字符是否是可打印的。
int ispunct(int c) 该函数检查所传的字符是否是标点符号字符。
int isspace(int c) 该函数检查所传的字符是否是空白字符。
int isupper(int c) 该函数检查所传的字符是否是大写字母。
int isxdigit(int c) 该函数检查所传的字符是否是十六进制数字。
int tolower(int c) 该函数把大写字母转换为小写字母。
int toupper(int c) 该函数把小写字母转换为大写字母。

说明:

  • 图形字符:字母、数字字符和标点符号字符的集合。
  • 可打印字符:字母、数字字符、标点符号字符和空格字符的集合。
  • 控制字符:在 ASCII 编码中,这些字符的八进制代码是从 000 到 037,以及 177(DEL)。
  • 空格字符:制表符、换行符、垂直制表符、换页符、回车符、空格符的集合。
  • 空白字符:包括空格符和制表符。

string.h

库变量

变量 说明
size_t 无符号整数类型,它是 sizeof 关键字的结果。

库宏

说明
NULL 是一个空指针常量的值。

字符串长度

函数 说明
size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符。

不受限制的字符串函数

函数 说明
char strcpy(char dest, const char *src) 把 src 所指向的字符串复制到 dest。
char strcat(char dest, const char *src) 把 src 所指向的字符串追加到 dest 所指向的字符串的结尾。
int strcmp(const char str1, const char str2) 把 str1 所指向的字符串和 str2 所指向的字符串进行比较。

长度受限的字符串函数

函数 说明
char strncpy(char dest, const char *src, size_t n) 把 src 所指向的字符串复制到 dest,最多复制 n 个字符。
char strncat(char dest, const char *src, size_t n) 把 src 所指向的字符串追加到 dest 所指向的字符串的结尾,直到 n 字符长度为止。
int strncmp(const char str1, const char str2, size_t n) 把 str1 和 str2 进行比较,最多比较前 n 个字节。

字符串查找

函数 说明
char strchr(const char str, int c) 在参数 str 所指向的字符串中搜索第一次出现字符 c(一个无符号字符)的位置。
char strrchr(const char str, int c) 在参数 str 所指向的字符串中搜索最后一次出现字符 c(一个无符号字符)的位置。
char strpbrk(const char str1, const char *str2) 检索字符串 str1 中第一个匹配字符串 str2 中字符的字符,不包含空结束字符。也就是说,依次检验字符串 str1 中的字符,当被检验字符在字符串 str2 中也包含时,则停止检验,并返回该字符位置。
char strstr(const char haystack, const char *needle) 在字符串 haystack 中查找第一次出现字符串 needle(不包含空结束字符)的位置。
size_t strspn(const char str1, const char str2) 检索字符串 str1 中第一个不在字符串 str2 中出现的字符下标。
size_t strcspn(const char str1, const char str2) 检索字符串 str1 开头连续有几个字符都不含字符串 str2 中的字符。
char strtok(char str, const char *delim) 分解字符串 str 为一组字符串,delim 为分隔符。

内存操作

函数 说明
void memchr(const void str, int c, size_t n) 在参数 str 所指向的字符串的前 n 个字节中搜索第一次出现字符 c(一个无符号字符)的位置。
int memcmp(const void str1, const void str2, size_t n) 把 str1 和 str2 的前 n 个字节进行比较。
void memcpy(void dest, const void *src, size_t n) 从 src 复制 n 个字符到 dest。
void memmove(void dest, const void *src, size_t n) 另一个用于从 src 复制 n 个字符到 dest 的函数。
void memset(void str, int c, size_t n) 复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符。

错误信息

函数 说明
char *strerror(int errnum) 从内部数组中搜索错误号 errnum,并返回一个指向错误消息字符串的指针。

其它

函数 说明
int strcoll(const char str1, const char str2) 把 str1 和 str2 进行比较,结果取决于 LC_COLLATE 的位置设置。
size_t strxfrm(char dest, const char src, size_t n) 根据程序当前的区域选项中的 LC_COLLATE 来转换字符串 src 的前 n 个字符,并把它们放置在字符串 dest 中。

Guess you like

Origin www.cnblogs.com/chay/p/11521402.html
Recommended