C语言库函数参考手册

合集下载

c语言math函数库手册

c语言math函数库手册

函数名称: abs函数原型: int abs(int x);函数功能: 求整数x的绝对值函数返回: 计算结果参数说明:所属文件: <>,<>使用范例:#include <>#include <>int main(){int number=-1234;printf("number: %d absolute value: %d",number,abs(number)); return 0;}@函数名称: fabs函数原型: double fabs(double x);函数功能: 求x的绝对值.函数返回: 计算结果参数说明:所属文件: <>使用范例:#include <>#include <>int main(){float number=;printf("number: %f absolute value: %f",number,fabs(number)); return 0;}@函数名称: cabs函数原型: double cabs(struct complex znum)函数功能: 求复数的绝对值函数返回: 复数的绝对值参数说明: zuum为用结构struct complex表示的复数,定义如下:struct complex{double m;double n;}所属文件: <>#include <>#include <>int main(){struct complex z;double val;=;=;val=cabs(z);printf("The absolute value of %.2lfi %.2lfj is %.2lf",,,val); return 0;}@函数名称: ceil函数原型: double ceil(double num)函数功能: 得到不小于num的最小整数函数返回: 用双精度表示的最小整数参数说明: num-实数所属文件: <>#include <>#include <>int main(){double number=;double down,up;down=floor(number);up=ceil(number);printf("original number %",number);printf("number rounded down %",down);printf("number rounded up %",up);return 0;}@函数名称: sin函数原型: double sin(double x);函数功能: 计算sinx的值.正弦函数函数返回: 计算结果参数说明: 单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result,x=;result=sin(x);printf("The sin() of %lf is %lf",x,result); return 0;}@函数名称: cos函数原型: double cos(double x);函数功能: 计算cos(x)的值.余弦函数.函数返回: 计算结果参数说明: x的单位为弧度所属文件: <>使用范例:#include <>#include <>int main()double result;double x=;result=cos(x);printf("The cosine of %lf is %lf",x,result);return 0;}@函数名称: tan函数原型: double tan(double x);函数功能: 计算tan(x)的值,即计算角度x的正切数值函数返回: 计算结果参数说明: x>=0单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result,x;x=;result=tan(x);printf("The tan of %lf is %lf",x,result);return 0;}@函数名称: asin函数原型: double asin(double x);函数功能: 计算sin^-1(x)的值.反正弦值函数函数返回: 计算结果参数说明: x应在 -1 到 1 范围内.单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=asin(x);printf("The arc sin of %lf is %lf",x,result); return 0;}@函数名称: acos函数原型: double acos(double x);函数功能: 计算cos^-1(x)的值,反余弦函数函数返回: 计算结果参数说明: x应在-1到1范围内.切记单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=acos(x);printf("The arc cosine of %lf is %lf",x,result); return 0;}@函数名称: atan函数原型: double atan(double x);函数功能: 计算tan^-1(x)的值.函数返回: 计算结果参数说明: 单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=atan(x);printf("The arc tangent of %lf is %lf",x,result);return 0;}@函数名称: atan2函数原型: double atan2(double x,double y);函数功能: 计算tan^-1/(x/y)的值.求x/y的反正切值.函数返回: 计算结果参数说明: 单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=,y=;result=atan2(y,x);printf("The arc tangent ratio of %lf is %lf",(y/x),result); return 0;}@函数名称: sinh函数原型: double sinh(double x);函数功能: 计算x的双曲正弦函数sinh(x)的值.函数返回: 计算结果参数说明: 单位为弧度所属文件: <>使用范例:#include <>#include <>int main(){double result,x=;result=sinh(x);printf("The hyperbolic sin() of %lf is %lf",x,result); return 0;}@函数名称: cosh函数原型: double cosh(double x);函数功能: 计算x的双曲余弦cosh(x)的值.函数返回: 计算结果参数说明:所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=cosh(x);printf("The hyperboic cosine of %lf is %lf",x,result); return 0;}@函数名称: tanh函数原型: double tanh(double x);函数功能: 计算x的双曲正切函数tanh(x)的值.函数返回: 计算结果参数说明: x>=0所属文件: <>使用范例:#include <>#include <>int main(){double result,x;x=;result=tanh(x);printf("The hyperbolic tangent of %lf is %lf",x,result); return 0;}@函数名称: exp函数原型: double exp(double x);函数功能: 求e的x次幂函数返回: 计算结果.幂的值参数说明: x-指数所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=exp(x);printf("'e' raised to the power of %lf(e^%lf)=%lf",x,x,result); return 0;}@函数名称: floor函数原型: double floor(double x);函数功能: 求出不大于x的最大整数.函数返回: 该整数的双精度实数参数说明:所属文件: <>使用范例:#include <>#include <>int main(){double number=;double down,up;down=floor(number);up=ceil(number);printf("original number %",number);printf("number rounded down %",down);printf("number rounded up %",up);return 0;}@函数名称: fmod函数原型: double fmod(double x,double y);函数功能: 求整数x/y的余数函数返回: 返回余数的双精度数.x/y的余数值.参数说明:所属文件: <>使用范例:#include <>#include <>int main(){double x=,y=;double result;result=fmod(x,y);printf("The remainder of (%lf/%lf) is %lf",x,y,result);return 0;}@函数名称: frexp函数原型: double frexp(double val,int *eptr);函数功能: 把双精度数val分解为数字部分(尾数)x和以2为底的指数n,即val=x*2^n,n存放在eptr指向的变量中.函数返回: 返回数字部分x,<=x且x<1参数说明: val-待分解的数所属文件: <>使用范例:#include <>#include <>int main(){double mantissa,number;int exponent;number=;mantissa=frexp(number,&exponent);printf("The number %lf is",number);printf("%lf times two to the",mantissa);printf("power of %d",exponent);return 0;}@函数名称: log函数原型: double log(double x);函数功能: 求logeX(e指的是以e为底),即计算x的自然对数(ln X) 函数返回: 计算结果参数说明:所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=log(x);printf("The natural log of %lf is %lf",x,result);return 0;}@函数名称: log10函数原型: double log10(double x);函数功能: 求log10x(10指的是以10为底).计算x的常用对数函数返回: 计算结果参数说明:所属文件: <>使用范例:#include <>#include <>int main(){double result;double x=;result=log10(x);printf("The common log of %lf is %lf",x,result);return 0;}@函数名称: modf函数原型: double modf(double val,double *iptr);函数功能: 把双精度数val分解为整数部分和小数部分,把整数部分存到iptr指向的单元. 函数返回: val的小数部分参数说明: val 待分解的数所属文件: <>使用范例:#include <>#include <>int main(){double fraction,integer;double number=;fraction=modf(number,&integer);printf("The whole and fractional parts of %lf are %lf and%lf",number,integer,fraction);}@函数名称: pow函数原型: double pow(double x,double y);函数功能: 计算以x为底数的y次幂,即计算x^y的值. 函数返回: 计算结果参数说明: x-底数,y-幂数所属文件: <>使用范例:#include <>#include <>int main(){double x=,y=;printf("%lf raised to %lf is %lf",x,y,pow(x,y)); return 0;}@函数名称: sqrt函数原型: double sqrt(double x);函数功能: 计算x的开平方.函数返回: 计算结果参数说明: x>=0所属文件: <>#include <>#include <>int main(){double x=,result;result=sqrt(x);printf("The square root of %lf is %lf",x,result); return 0;}@函数名称: hypot函数原型: double hypot(double x,double y)函数功能: 已知直角三角形两个直角边长度,求斜边长度函数返回: 斜边长度参数说明: x,y-直角边长度所属文件: <>#include <>#include <>int main(){double result;double x=;double y=;result=hypot(x,y);printf("The hypotenuse is: %lf",result);return 0;}@函数名称: poly函数原型: double poly(double x,int degree,double coeffs[])函数功能: 计算多项式函数返回: 多项式的计算结果参数说明: 计算c[n]*x^n+c[n-1]x^n-1+.....+c[1]*x+c[0]所属文件: <>#include <>#include <>int main(){double array[]={,,,};double result;result=poly,3,array);printf("The polynomial: x**3 - **2 + 5x - 1 at is %lf",result); return 0;}@函数名称: matherr函数原型: int matherr(struct exception *e)函数功能: 数学错误计算处理程序函数返回:参数说明: 该函数不能被直接调用,而是被库函数_matherr()调用所属文件: <>#include<>int matherr(struct exception *a){return 1;}@函数名称: ldexp函数原型: double ldexp(double x,int exponent)函数功能: 计算x*2的exponent次幂,即2*pow(2,exponent)的数值函数返回:参数说明:所属文件: <>#include <>#include <>int main(){double value;double x=2;value=ldexp(x,3);printf("The ldexp value is: %lf",value);return 0;}int abs(int i) 返回整型参数i的绝对值double cabs(struct complex znum) 返回复数znum的绝对值double fabs(double x) 返回双精度参数x的绝对值long labs(long n) 返回长整型参数n的绝对值double exp(double x) 返回指数函数ex的值double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中double ldexp(double value,int exp); 返回value*2exp的值double log(double x) 返回logex的值double log10(double x) 返回log10x的值double pow(double x,double y) 返回xy的值double pow10(int p) 返回10p的值double sqrt(double x) 返回+√x的值double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度double atan(double x) 返回x的反正切tan-1(x)值,x为弧度double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度double cos(double x) 返回x的余弦cos(x)值,x为弧度double sin(double x) 返回x的正弦sin(x)值,x为弧度double tan(double x) 返回x的正切tan(x)值,x为弧度double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度double hypot(double x,double y) 返回直角三角形斜边的长度(z),x和y为直角边的长度,z2=x2+y2double ceil(double x) 返回不小于x的最小整数double floor(double x) 返回不大于x的最大整数void srand(unsigned seed) 初始化随机数发生器int rand() 产生一个随机数并返回这个数double poly(double x,int n,double c[])从参数产生一个多项式double modf(double value,double *iptr)将双精度数value分解成尾数和阶double fmod(double x,double y) 返回x/y的余数double frexp(double value,int *eptr) 将双精度数value分成尾数和阶double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数char *ecvt(double value,int ndigit,int *decpt,int *sign)将浮点数value转换成字符串并返回该字符串char *fcvt(double value,int ndigit,int *decpt,int *sign)将浮点数value转换成字符串并返回该字符串char *gcvt(double value,int ndigit,char *buf)将数value转换成字符串并存于buf中,并返回buf的指针char *ultoa(unsigned long value,char *string,int radix)将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数char *ltoa(long value,char *string,int radix)将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数char *itoa(int value,char *string,int radix)将整数value转换成字符串存入string,radix为转换时所用基数double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0 double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数, long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,并返回这个数,int matherr(struct exception *e)用户修改数学错误返回信息函数(没有必要使用)double _matherr(_mexcep why,char *fun,double *arg1p, double *arg2p,double retval)用户修改数学错误返回信息函数(没有必要使用)unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态void _fpreset() 重新初使化浮点数学程序包unsigned int _status87() 返回浮点状态字。

C语言常用的库函数表

C语言常用的库函数表

附录C C语言常用的库函数
库函数并不是C语言的一部分,它是由编译系统根据一般用户的需要编制并提供给用户使用的一组程序;每一种C编译系统都提供了一批库函数,不同的编译系统所提供的库函数的数目和函数名以及函数功能是不完全相同的;ANSI C标准提出了一批建议提供的标准库函数;它包括了目前多数C编译系统所提供的库函数,但也有一些是某些C编译系统未曾实现的;考虑到通用性,本附录列出ANSI C建议的常用库函数;
由于C库函数的种类和数目很多,例如还有屏幕和图形函数、时间日期函数、与系统有关的函数等,每一类函数又包括各种功能的函数,限于篇幅,本附录不能全部介绍,只从教学需要的角度列出最基本的;读者在编写C程序时可根据需要,查阅有关系统的函数使用手册;
1.数学函数
使用数学函数时,应该在源文件中使用预编译命令:
2.字符函数
在使用字符函数时,应该在源文件中使用预编译命令:
3.字符串函数
使用字符串中函数时,应该在源文件中使用预编译命令:
4.输入输出函数
在使用输入输出函数时,应该在源文件中使用预编译命令:
5.动态存储分配函数
在使用动态存储分配函数时,应该在源文件中使用预编译命令:include <stdlib.h>或include "stdlib.h"
6.其他函数
有些函数由于不便归入某一类,所以单独列出;使用这些函数时,应该在源文件中使用预编译命令:。

C语言函数参考手册

C语言函数参考手册

C语言函数参考手册一、概述C语言是一种通用的、面向过程的程序设计语言,广泛应用于系统编程和应用软件开发等领域。

在C语言中,函数是非常重要的组成部分,通过函数可以实现代码的模块化和重复使用。

本手册旨在为C语言开发者提供函数相关信息的参考,包括常用函数的用法、参数说明和返回值等。

二、函数的声明函数声明是指在使用函数之前,需要先声明函数的存在及函数的参数类型和返回值类型。

函数声明通常位于源文件的开头部分,以便在其他代码中使用。

1. 函数声明的一般格式如下:返回值类型函数名(参数列表);2. 示例:int max(int a, int b);void printHello();三、函数的定义函数定义是指实现函数的功能代码,并且包含函数的参数和返回值类型的明确说明。

函数定义通常位于源文件的主体部分。

1. 函数定义的一般格式如下:返回值类型函数名(参数列表) {函数体代码return 返回值;}2. 示例:int max(int a, int b) {if (a > b) {return a;} else {return b;}}void printHello() {printf("Hello, world!\n");}四、函数的参数函数的参数是指在函数的括号内声明的变量,用于接受调用函数时传递的值。

函数的参数可以有多个,也可以没有参数。

1. 参数的声明格式如下:参数类型参数名2. 示例:int add(int a, int b);void printName(char* name);五、函数的返回值函数的返回值是指函数执行完成后返回的结果。

返回值可以是任何数据类型,如整数、浮点数、字符等。

函数的返回值可以有多种情况,根据具体逻辑来确定。

1. 返回值的声明格式如下:返回值类型2. 示例:int max(int a, int b);double calculateAverage(int array[], int length);六、常用函数C语言提供了许多常用的函数库,通过这些函数可以实现各种功能。

C语言中的库函数使用指南

C语言中的库函数使用指南

C语言中的库函数使用指南库函数在C语言中扮演着至关重要的角色,可以提供各种各样的功能和方法,帮助我们更高效地编写程序。

本文将为您提供一份C语言库函数的使用指南,帮助您更好地掌握这些常用的函数。

一、输入输出函数1. printf()printf()函数是C语言用于输出信息的常用函数。

它可以按照指定的格式将数据输出到屏幕上。

例如:```c#include<stdio.h>int main(){int num = 10;printf("The number is %d\n", num);return 0;}```2. scanf()scanf()函数是C语言用于从键盘上接收用户输入的函数。

通过指定变量的地址,将用户输入的数据保存到相应的变量中。

例如:```c#include<stdio.h>int main(){int num;printf("Please enter a number: ");scanf("%d", &num);printf("You entered: %d\n", num);return 0;}```二、字符串处理函数1. strlen()strlen()函数用于计算字符串的长度,即该字符串中字符的个数(不包括字符串结束符'\0')。

例如:```c#include<stdio.h>#include<string.h>int main(){char str[] = "Hello, world!";int length = strlen(str);printf("The length of the string is %d\n", length);return 0;}```2. strcpy()和strcat()strcpy()函数用于将一个字符串复制到另一个字符串中。

C语言常用标准库函数

C语言常用标准库函数

C语⾔常⽤标准库函数数学函数:在math.h中abs(x) :求整型数x的绝对值cos(x):x(弧度)的余弦fabs(x):求浮点数x的绝对值ceil(x):求不⼩于x的最⼩整数floor(x):求不⼤于x的最⼩整数log(x):求x的⾃然对数log10(x):求x的对数(底为10)pow(x,y):求x的y次⽅sin(x):求x(弧度)的正弦sqrt(x):求x的平⽅根字符处理函数:在ctype.h中声明int isdigit(int c):判断是否是数字字符int isalpha(int c):判断是否是⼀个字母int isalnum(int c):判断是否是⼀个数字或字母int islower(int c):判断是否是⼀个⼩写字母int isupper(int c):判断是否是⼀个⼤写字母int toupper(int c):转换成⼤写字母int tolower(int c):转换成⼩写字母字符串处理和内存操作函数声明于string.h中char *strchr(char *s,int c):如果s中包含字符c,则返回⼀个指向s第⼀次出现的该字符的指针,否则返回NULLchar *strstr(char *s1,char *s2):如果s2是s1的⼀个⼦串,则返回⼀个指向s1中⾸次出现s2的位置的指针,否则返回NULLchar *strlwr(char *s):将s中的字母都变成⼩写cahr *strupr(char *s):将s中的字母都变成⼤写char *strcpy(char *s1,char *s2):将字符串s2的内容复制到s1中去char *strncpy(char *s1,char *s2,int n):将字符串s2的内容复制到s1中去,但是最多复制n个字节,如果复制字节数达到n,那么就不会往s1中写⼊结尾的'\0'char *strcat(cahr *s1,char *s2):将字符串s2添加到s1末尾int strcmp(char *s1,char *s2):⽐较两个字符串,⼤⼩写相关int stricmp(char *s1,char *s2):⽐较两个字符串,⼤⼩写⽆关int strlen(const char *string):计算字符串的长度int strncmp(const char *string1,const char *string2,size_t count):分别取两个字符串的前count个字符作为字符串,⽐较他们的⼤⼩char *strrev(char *string):将字符串string前后颠倒void *memcpy(void *s1,void *s2,int n):将内存地址s2处的n个字节内容复制到内存地址s1void *memset(void *s,int c,int n):将内存地址s开始的n个字节全部置为c不过只能赋制为0,1fill(a,a+n,c):能够赋值为任意值字符串转换函数:定义在stdlib.h中int atoi(char *s):将字符串s转换为整型数double atof(char *s):将字符串s⾥的内容转换为浮点数char * itoa(int value,char *string,int radix):将整型值value以radix进制表⽰法写⼊string。

c 标准库函数手册

c 标准库函数手册

c 标准库函数手册C 标准库函数手册。

C 标准库函数是 C 语言提供的一组函数库,它包含了一系列常用的函数,可以帮助程序员更高效地完成各种任务。

本手册将介绍 C 标准库函数的常用函数及其用法,帮助读者更加深入地理解和运用这些函数。

一、stdio.h。

stdio.h 是 C 语言中用来进行输入输出操作的头文件,它包含了一系列与标准输入输出相关的函数。

其中,最常用的函数包括 printf、scanf、fopen、fclose 等。

这些函数可以帮助程序员进行屏幕输出、键盘输入、文件读写等操作。

例如,printf 函数可以用来向屏幕输出格式化的字符串,而 scanf 函数则可以用来从键盘接收输入并存储到变量中。

二、stdlib.h。

stdlib.h 是 C 语言中的标准库头文件之一,它包含了一系列与内存分配、随机数生成、字符串转换等功能相关的函数。

其中,最常用的函数包括 malloc、free、rand、atoi 等。

这些函数可以帮助程序员进行动态内存分配、随机数生成、字符串转换等操作。

例如,malloc 函数可以用来动态分配指定大小的内存空间,而 rand 函数则可以用来生成一个指定范围内的随机数。

三、math.h。

math.h 是 C 语言中的标准数学库头文件,它包含了一系列与数学运算相关的函数。

其中,最常用的函数包括 sin、cos、sqrt、pow 等。

这些函数可以帮助程序员进行各种数学运算,如三角函数计算、平方根计算、幂运算等。

例如,sin 函数可以用来计算给定角度的正弦值,而 sqrt 函数则可以用来计算一个数的平方根。

四、string.h。

string.h 是 C 语言中的标准字符串库头文件,它包含了一系列与字符串操作相关的函数。

其中,最常用的函数包括 strlen、strcpy、strcat、strcmp 等。

这些函数可以帮助程序员进行字符串的长度计算、复制、连接、比较等操作。

例如,strlen 函数可以用来计算一个字符串的长度,而 strcpy 函数则可以用来将一个字符串复制到另一个字符串中。

c语言常用函数手册 chm格式

c语言常用函数手册 chm格式

c语言常用函数手册 chm格式/downinfo/19389.html全都很详细例如下面的函数名: abort功能: 异常终止一个进程用法: void abort(void);程序例:#include <stdio.h>#include <stdlib.h>int main(void){printf("Calling abort()\n");abort();return 0; /* This is never reached */}函数名: abs功能: 求整数的绝对值用法: int abs(int i);程序例:#include <stdio.h>#include <math.h>int main(void){int number = -1234;printf("number: %d absolute value: %d\n", number, abs(number)); return 0;}函数名: absread, abswirte功能: 绝对磁盘扇区读、写数据用法: int absread(int drive, int nsects, int sectno, void *buffer); int abswrite(int drive, int nsects, in tsectno, void *buffer);程序例:/* absread example */#include <stdio.h>#include <conio.h>#include <process.h>#include <dos.h>int main(void){int i, strt, ch_out, sector;char buf[512];printf("Insert a diskette into drive A and press any key\n");getch();sector = 0;if (absread(0, 1, sector, &buf) != 0){perror("Disk problem");exit(1);}printf("Read OK\n");strt = 3;for (i=0; i<80; i++){ch_out = buf[strt+i];putchar(ch_out);}printf("\n");return(0);}函数名: access功能: 确定文件的访问权限用法: int access(const char *filename, int amode);程序例:#include <stdio.h>#include <io.h>int file_exists(char *filename);int main(void){printf("Does NOTEXIST.FIL exist: %s\n",file_exists("NOTEXISTS.FIL") ? "YES" : "NO");return 0;}int file_exists(char *filename){return (access(filename, 0) == 0);}函数名: acos功能: 反余弦函数用法: double acos(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = acos(x);printf("The arc cosine of %lf is %lf\n", x, result); return 0;}函数名: allocmem功能: 分配DOS存储段用法: int allocmem(unsigned size, unsigned *seg);程序例:#include <dos.h>#include <alloc.h>#include <stdio.h>int main(void){unsigned int size, segp;int stat;size = 64; /* (64 x 16) = 1024 bytes */stat = allocmem(size, &segp);if (stat == -1)printf("Allocated memory at segment: %x\n", segp);elseprintf("Failed: maximum number of paragraphs available is %u\n",stat);return 0;}函数名: arc功能: 画一弧线用法: void far arc(int x, int y, int stangle, int endangle, int radius); 程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int stangle = 45, endangle = 135;int radius = 100;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult(); /* an error occurred */if (errorcode != grOk){printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */ }midx = getmaxx() / 2;midy = getmaxy() / 2;setcolor(getmaxcolor());/* draw arc */arc(midx, midy, stangle, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: asctime功能: 转换日期和时间为ASCII码用法: char *asctime(const struct tm *tblock);程序例:#include <stdio.h>#include <string.h>#include <time.h>int main(void){struct tm t;char str[80];/* sample loading of tm structure */t.tm_sec = 1; /* Seconds */t.tm_min = 30; /* Minutes */t.tm_hour = 9; /* Hour */t.tm_mday = 22; /* Day of the Month */t.tm_mon = 11; /* Month */t.tm_year = 56; /* Year - does not include century */t.tm_wday = 4; /* Day of the week */t.tm_yday = 0; /* Does not show in asctime */t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime *//* converts structure to null terminatedstring */strcpy(str, asctime(&t));printf("%s\n", str);return 0;}函数名: asin功能: 反正弦函数用法: double asin(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = asin(x);printf("The arc sin of %lf is %lf\n", x, result);return(0);}函数名: assert功能: 测试一个条件并可能使程序终止用法: void assert(int test);程序例:#include <assert.h>#include <stdio.h>#include <stdlib.h>struct ITEM {int key;int value;};/* add item to list, make sure list is not null */ void additem(struct ITEM *itemptr) {assert(itemptr != NULL);/* add item to list */}int main(void){additem(NULL);return 0;}函数名: atan功能: 反正切函数用法: double atan(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = atan(x);printf("The arc tangent of %lf is %lf\n", x, result);return(0);}函数名: atan2功能: 计算Y/X的反正切值用法: double atan2(double y, double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 90.0, y = 45.0;result = atan2(y, x);printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);return 0;}函数名: atexit功能: 注册终止函数用法: int atexit(atexit_t func);程序例:#include <stdio.h>#include <stdlib.h>void exit_fn1(void){printf("Exit function #1 called\n"); }void exit_fn2(void){printf("Exit function #2 called\n"); }int main(void){/* post exit function #1 */atexit(exit_fn1);/* post exit function #2 */atexit(exit_fn2);return 0;}函数名: atof功能: 把字符串转换成浮点数用法: double atof(const char *nptr); 程序例:#include <stdlib.h>#include <stdio.h>int main(void){float f;char *str = "12345.67";f = atof(str);printf("string = %s float = %f\n", str, f);return 0;}函数名: atoi功能: 把字符串转换成长整型数用法: int atoi(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){int n;char *str = "12345.67";n = atoi(str);printf("string = %s integer = %d\n", str, n);return 0;}函数名: atol功能: 把字符串转换成长整型数用法: long atol(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){long l;char *str = "98765432";l = atol(lstr);printf("string = %s integer = %ld\n", str, l);return(0);}。

C语言参考手册之函数库

C语言参考手册之函数库

版权说明:本资料内容摘录自《C程序设计语言(第二版)》K&R著 徐宝文 李志译 尤晋元审校机械工业出版社出版 一书。

版权属原作者和出版社所有。

制作本资料为了我本人学习和参考,非商业用途。

建议读者阅读原书学习比较好,它更详细。

目录:附录B:标准库介绍标准库的组成,及使用注意。

B.1 输入与输出:<stdio.h>主要介绍流的概念等。

B.1.1 文件操作主要介绍 fopen(), freopen(), fflush(), fclose(), remove(), rename(), tmpfile(), tmpnam(), setvbuf(),setbuf()等。

B.1.2 格式化输出主要介绍 printf(), fprintf(), sprintf(), vprintf(), vfprintf(), vsprintf()等。

B.1.3 格式化输入主要介绍 fscanf(), scanf(), sscanf()等。

B.1.4 字符输入/输出函数主要介绍 fgetc(), fgets(), fputc(), fputs(), getc(), gets(), putc(),puts(), putchar(), ungetc()等。

B.1.5 直接输入输出主要介绍 fread()和fwrite()。

B.1.6 文件定位函数主要介绍 fseek(), ftell(), rewind(), fgetpos(), fsetpos()等。

B.1.7 错误处理函数主要介绍 clearerr(), feof(), ferror(), perror()等。

B.2 字符类别测试:<ctype.h>主要介绍 isalnum(c), isalpha(c), iscntrl(c), isdigit(c), … , tolower(c), toupper(c)等。

B.3 字符串函数:<string.h>主要介绍 strcpy(),strncpy(), strcat(), strncat(), strcmp(), strncmp(), strchar(), strrchr(), strspn(), strcspn(), strpbrk(), strstr(), strlen(), strerror(), strtok()等。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C语言库函数参考手册转载说明:可能有些函数已经过时,但从学习的角度来看,还是有一定的参考价值。

分类函数,所在函数库为ctype.hint isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')返回非0值,否则返回0int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0int iscntrl(int ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)返回非0值,否则返回0int isdigit(int ch) 若ch是数字('0'-'9')返回非0值,否则返回0int isgraph(int ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0 int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0int isprint(int ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0 int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0int isspace(int ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'),走纸换行('\f'),垂直制表符('\v'),换行符('\n')返回非0值,否则返回0int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值,否则返回0int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z')int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')数学函数,所在函数库为math.h、stdlib.h、string.h、float.hint abs(int i) 返回整型参数i的绝对值double cabs(struct complex znum) 返回复数znum的绝对值double fabs(double x) 返回双精度参数x的绝对值long labs(long n) 返回长整型参数n的绝对值double exp(double x) 返回指数函数ex的值double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中double ldexp(double value,int exp); 返回value*2exp的值double log(double x) 返回logex的值double log10(double x) 返回log10x的值double pow(double x,double y) 返回xy的值double pow10(int p) 返回10p的值double sqrt(double x) 返回+√x的值double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度double atan(double x) 返回x的反正切tan-1(x)值,x为弧度double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度double cos(double x) 返回x的余弦cos(x)值,x为弧度double sin(double x) 返回x的正弦sin(x)值,x为弧度double tan(double x) 返回x的正切tan(x)值,x为弧度double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度double hypot(double x,double y) 返回直角三角形斜边的长度(z),x和y为直角边的长度,z2=x2+y2double ceil(double x) 返回不小于x的最小整数double floor(double x) 返回不大于x的最大整数void srand(unsigned seed) 初始化随机数发生器int rand() 产生一个随机数并返回这个数double poly(double x,int n,double c[])从参数产生一个多项式double modf(double value,double *iptr)将双精度数value分解成尾数和阶double fmod(double x,double y) 返回x/y的余数double frexp(double value,int *eptr) 将双精度数value分成尾数和阶double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数char *ecvt(double value,int ndigit,int *decpt,int *sign)将浮点数value转换成字符串并返回该字符串char *fcvt(double value,int ndigit,int *decpt,int *sign)将浮点数value转换成字符串并返回该字符串char *gcvt(double value,int ndigit,char *buf)将数value转换成字符串并存于buf中,并返回buf的指针char *ultoa(unsigned long value,char *string,int radix)将无符号整型数value转换成字符串并返回该字符串,radix为转换时所用基数char *ltoa(long value,char *string,int radix)将长整型数value转换成字符串并返回该字符串,radix为转换时所用基数char *itoa(int value,char *string,int radix)将整数value转换成字符串存入string,radix为转换时所用基数double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0int atoi(char *nptr) 将字符串nptr转换成整型数, 并返回这个数,错误返回0long atol(char *nptr) 将字符串nptr转换成长整型数,并返回这个数,错误返回0 double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数, long strtol(char *str,char **endptr,int base)将字符串str转换成长整型数,并返回这个数,int matherr(struct exception *e)用户修改数学错误返回信息函数(没有必要使用)double _matherr(_mexcep why,char *fun,double *arg1p,double *arg2p,double retval)用户修改数学错误返回信息函数(没有必要使用)unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态void _fpreset() 重新初使化浮点数学程序包unsigned int _status87() 返回浮点状态字目录函数,所在函数库为dir.h、dos.hint chdir(char *path) 使指定的目录path(如:"C:\\WPS")变成当前的工作目录,成功返回0int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功返回0pathname为指定的目录名和文件名,如"C:\\WPS\\TXT"ffblk为指定的保存文件信息的一个结构,定义如下:┏━━━━━━━━━━━━━━━━━━┓┃struct ffblk ┃┃{ ┃┃ char ff_reserved[21]; /*DOS保留字*/┃┃ char ff_attrib; /*文件属性*/ ┃┃ int ff_ftime; /*文件时间*/ ┃┃ int ff_fdate; /*文件日期*/ ┃┃ long ff_fsize; /*文件长度*/ ┃┃ char ff_name[13]; /*文件名*/ ┃┃} ┃┗━━━━━━━━━━━━━━━━━━┛attrib为文件属性,由以下字符代表┏━━━━━━━━━┳━━━━━━━━┓┃FA_RDONLY 只读文件┃FA_LABEL 卷标号┃┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录┃┃FA_SYSTEM 系统文件┃FA_ARCH 档案┃┗━━━━━━━━━┻━━━━━━━━┛例:struct ffblk ff;findfirst("*.wps",&ff,FA_RDONLY);int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0void fumerge(char *path,char *drive,char *dir,char *name,char *ext) 此函数通过盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),文件名name(TC、WPS等),扩展名ext(.EXE、.COM等)组成一个文件名存与path中.int fnsplit(char *path,char *drive,char *dir,char *name,char *ext) 此函数将文件名path分解成盘符drive(C:、A:等),路径dir(\TC、\BC\LIB等),文件名name(TC、WPS等),扩展名ext(.EXE、.COM等),并分别存入相应的变量中.int getcurdir(int drive,char *direc) 此函数返回指定驱动器的当前工作目录名称drive 指定的驱动器(0=当前,1=A,2=B,3=C等)direc 保存指定驱动器当前工作路径的变量成功返回0char *getcwd(char *buf,iint n) 此函数取当前工作目录并存入buf中,直到n个字节长为为止.错误返回NULLint getdisk() 取当前正在使用的驱动器,返回一个整数(0=A,1=B,2=C等)int setdisk(int drive) 设置要使用的驱动器drive(0=A,1=B,2=C等), 返回可使用驱动器总数int mkdir(char *pathname) 建立一个新的目录pathname,成功返回0int rmdir(char *pathname) 删除一个目录pathname,成功返回0char *mktemp(char *template) 构造一个当前目录上没有的文件名并存于template中char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路径,,此函数使用DOS的PATH变量,未找到文件返回NULL进程函数,所在函数库为stdlib.h、process.hvoid abort() 此函数通过调用具有出口代码3的_exit写一个终止信息于stderr,并异常终止程序。

相关文档
最新文档