牛骨文教育服务平台(让学习变的简单)
博文笔记

常用ANSI C语言标准库函数汇总(一)

创建时间:2017-04-30 投稿人: 浏览次数:1203

C语言被发明出来时并没有什么库函数,随着C语言的流行,越来越多的厂商和组织开始提供C语言的编译器,同时把经常用到的函数封装成“库”的形式发布。后来,美国国家标准协会(ANSI)制定了C语言的标准,同时也制定了一定数量的库,称之为ANSI C语言标准函数库。本文将简要介绍以下几种常见库函数的汇总。(所有函数名按照首字母顺序排列)

  • 数学函数
  • 字符函数
  • 字符串函数
  • 动态存储分配函数
  • 其他函数
  • 输入/输出函数

1.数学函数

函数名 函数原型 功能 返回值
acos double acos(double x) 计算arccosx的值,其中-1<=x<=1 计算结果
asin double asin(double x) 计算arcsinx的值,其中-1<=x<=1 计算结果
atan double atan(double x) 计算arctanx的值 计算结果
atan2 double atan2(double x,double y) 计算arctanx/y的值 计算结果
cos double cos(double x) 计算cosx的值,x的单位为弧度 计算结果
cosh double cosh(double x) 计算x的双曲余弦cosh x的值 计算结果
exp double exp(double x) 计算e^x的值 计算结果
fabs double fabs(double x) 计算x的绝对值 计算结果
floor double floor(double x) 求出不大于x的最大整数 该整数的双精度实数
fmod double fmod(double x,double y) 求x/y的余数 余数双精度实数
frexp double frexp(double val,int *eptr) 把双精度数val分解成数字部分(尾数)和以2为底的指数,即val=x*2^n,n存放在eptr指向的变量中 数字部分x,0.5<=x<1
log double log(double x) 求lnx的值 计算结果
log10 double log10(double x) 求log10zx的值 计算结果
modf double modf(double val,int *iptr) 把双精度数val分解成数字部分和小数部分,把整数部分存放在ptr指向的变量中 val的小数部分
pow double pow(double x,double y) 求x^y的值 计算结果
sin double sin(double x) 计算sinx的值,其中x的单位为弧度 计算结果
sinh double sinh(double x) 计算x的双曲正弦函数sinh x的值 计算结果
sqrt double sqrt(double x) 计算x^1/2 ,x>=0 计算结果
tan double tan(double x) 计算tanx的值,x的单位为弧度 计算结果
tanh double tanh(double x) 计算x的双曲正切函数tanh x的值 计算结果

2.字符函数

在使用字符函数时,应该在源文件中使用预编译命令:#include “ctype.h”
函数名 函数原型 功能 返回值
isalnum int isalnum(int ch) 检查ch是否是字母或数字 是字母或数字返回1,否则返回0
isalpha int isalpha(int ch) 检查ch是否是字母 是字母返回1,否则返回0
iscntrl int iscntrl (int ch) 检查ch是否控制字符(其ASCII码在0和0xlF之间) 是控制字符返回1,否则返回0
isdigit int isdigit (int ch) 检查ch是否是数字 是数字返回1,否则返回0
isgraph int isgraph (int ch) 检查ch是否是可输出字符(其ASCII码在0x21和0x7e之间),不包括空格 是可输出字符返回1,否则返回0
islower int islower(int ch) 检查ch是否是小写字母 是小写字母 1,否则返回0
isprint int isprint (int ch) 检查ch是否是可输出字符(其ASCII码在0x21和0x7e之间),不包括空格 是可输出字符返回1,否则返回0
ispunct int ispunct (int ch) 检查ch是否是标点字符(不包括空格),即除字母、数字和空格以外的所有可输出字符 是标点返回1,否则返回0
isspace int isspace (int ch) 检查ch是否是空格、跳格符(制表符)或换行符 是返回1,否则返回0
isupper int isupper(int ch) 检查ch是否是大写字母 是大写字母返回1,否则返回0
isxdigit int isxdigit (int ch) 检查ch是否是一个16进制数字 是返回1,否则返回
tolower int tolower (int ch) 将ch字符转换为小写字母 返回ch对应的小写字母
toupper int toupper (int ch) 将ch字符转换为大写字母 返回ch对应的大写字母
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。