C常用标准库及函数

常用头文件:

stdio.h

stdlib.h

ctype.h

string.h

math.h

system.h


1、stdio库:主要功能是输入输出操作,包括文件输入输出,标准输入输出。

输出函数: int puts(const char* str) 把一个字符串写出到标准输出

int printf(char *format,args,…)  把args,…的值以format指定的格式输出到标准输出设备,输出字符的个数

用\0替换为\n换行符


输入函数:char* gets(char* str)从标准输入读一行数据知道换行符才结束

FILE *fopen(char *filename,char *mode)  以mode指定的方式打开名为filename的文件,返回值:成功,返回文件指针(文件信息区的起始地址),否则返回NULL

将\n替换为\0


2、ctype库

字符函数:定义了一批C语言字符分类函数,用于测试字符是否属于特定的字符。

字符测试函数:

函数原型均为 int is***(int a)

只能正确处理 【0,127】之间的数值

参数为int,任何实参均被提升成整型

字符映射函数:

函数原型 int to***(int a)

对参数进行检测,符合范围则转换,否则不变。

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

#include <ctype.h>

函数原型说明

功能

返回值

int isalnum(int ch)

检查ch是否为字母或数字

是,返回1;否则返回0

int isalpha(int ch)

检查ch是否为字母

是,返回1;否则返回0

int iscntrl(int ch)

检查ch是否为控制字符

是,返回1;否则返回0

int isdigit(int ch)

检查ch是否为数字

是,返回1;否则返回0

int isgraph(int ch)

检查ch是否为ASCII码值在ox21到ox7e的可打印字符(即不包含空格字符)

是,返回1;否则返回0

int islower(int ch)

检查ch是否为小写字母

是,返回1;否则返回0

int isprint(int ch)

检查ch是否为包含空格符在内的可打印字符

是,返回1;否则返回0

int ispunct(int ch)

检查ch是否为除了空格、字母、数字之外的可打印字符

是,返回1;否则返回0

int isspace(int ch)

检查ch是否为空格、制表或换行符

是,返回1;否则返回0

int isupper(int ch)

检查ch是否为大写字母

是,返回1;否则返回0

int isxdigit(int ch)

检查ch是否为16进制数

是,返回1;否则返回0

int tolower(int ch)

把ch中的字母转换成小写字母

返回对应的小写字母

int toupper(int ch)

把ch中的字母转换成大写字母

返回对应的大写字母

3、字符串处理函数库,#include <string.h>

函数原型说明

功能

返回值

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

把字符串s2接到s1后面

s1所指地址

char *strchr(char *s,int ch)

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

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

int strcmp(char *s1,char *s2)

对s1和s2所指字符串进行比较

s1<s2,返回负数;s1= =s2,返回0;s1>s2,返回正数

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

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

s1 所指地址

unsigned strlen(char *s)

求字符串s的长度

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

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

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

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

4、math.h 数学库

函数原型说明

功能

返回值

说明

int abs( int x)

求整数x的绝对值

计算结果

 

double fabs(double x)

求双精度实数x的绝对值

计算结果

 

double acos(double x)

计算cos-1(x)的值

计算结果

x在-1~1范围内

double asin(double x)

计算sin-1(x)的值

计算结果

x在-1~1范围内

double atan(double x)

计算tan-1(x)的值

计算结果

 

double atan2(double x)

计算tan-1(x/y)的值

计算结果

 

double cos(double x)

计算cos(x)的值

计算结果

x的单位为弧度

double cosh(double x)

计算双曲余弦cosh(x)的值

计算结果

 

double exp(double x)

求ex的值

计算结果

 

double fabs(double x)

求双精度实数x的绝对值

计算结果

 

double floor(double x)

求不大于双精度实数x的最大整数

 

 

double fmod(double x,double y)

求x/y整除后的双精度余数

 

 

double frexp(double val,int *exp)

把双精度val分解尾数和以2为底的指数n,即val=x*2n,n存放在exp所指的变量中

返回位数x

0.5≤x<1

 

double log(double x)

求㏑x

计算结果

x>0

double log10(double x)

求log10x

计算结果

x>0

double modf(double val,double *ip)

把双精度val分解成整数部分和小数部分,整数部分存放在ip所指的变量中

返回小数部分

 

double pow(double x,double y)

计算xy的值

计算结果

 

double sin(double x)

计算sin(x)的值

计算结果

x的单位为弧度

double sinh(double x)

计算x的双曲正弦函数sinh(x)的值

计算结果

 

double sqrt(double x)

计算x的开方

计算结果

x≥0

double tan(double x)

计算tan(x)

计算结果

 

double tanh(double x)

计算x的双曲正切函数tanh(x)的值

计算结果

 

5、stdlib.h

字符串转换

double atof (const char*);

int atoi (const char*);
long atol (const char*);
double strtod (const char*, char**);
long strtol (const char*, char**, int);

unsigned long strtoul (const char*, char**, int);

随机数

内存管理

环境接口:

void abort (void);
void exit (int);
int atexit (void (*)(void));

int system (const char*);
char* getenv (const char*);


  • 6
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值