C语言中函数名
- 格式:doc
- 大小:354.50 KB
- 文档页数:24
C语⾔math.h中常⽤函数1.绝对值2.取整和取余3.三⾓函数4.反三⾓函数5.双曲三⾓函数6.指数和对数7.标准化浮点数8.多项式9.数学错误计算处理1.绝对值函数原型: int abs(int x);函数功能: 求整数x的绝对值int number=-1234;abs(number);函数原型:double fabs(double x);函数功能:求浮点数x的绝对值.float number=-1234.0;fabs(number);函数原型:double cabs(struct complex znum)函数功能:求复数的绝对值参数说明:zuum为⽤结构struct complex表⽰的复数,定义如下:struct complex{double m;double n;}#include <stdio.h>#include <math.h>int main(){struct complex z;double val;z.x=2.0;z.y=1.0;val=cabs(z);printf("The absolute value of %.2lfi %.2lfj is %.2lf",z.x,z.y,val);return 0;}2.取整和取余函数原型: double ceil(double num)函数功能: 得到不⼩于num的最⼩整数函数返回: ⽤双精度表⽰的最⼩整数函数原型: double floor(double x);函数功能: 求出不⼤于x的最⼤整数.函数返回: 该整数的双精度实数函数原型:double fmod (double x, double y); 返回两参数相除x/y的余数,符号与x相同。
如果y为0,则结果与具体的额实现有关int main(){double number=123.54;double down,up;down=floor(number);up=ceil(number);printf("original number %10.2lf",number);//123.54printf("number rounded down %10.2lf",down); //123printf("number rounded up %10.2lf",up); //124return 0;}函数名称: modf函数原型: double modf(double val,double *iptr);函数功能: 把双精度数val分解为整数部分和⼩数部分,把整数部分存到iptr指向的单元.函数返回: val的⼩数部分参数说明: val 待分解的数所属⽂件: <math.h>使⽤范例:#include <math.h>#include <stdio.h>int main(){double fraction,integer;double number=100000.567;fraction=modf(number,&integer);printf("The whole and fractional parts of %lf are %lf and %lf",number,integer,fraction); return 0;}3.三⾓函数函数原型: double sin(double x);函数功能: 计算sinx的值.正弦函数函数原型: double cos(double x);函数功能: 计算cos(x)的值.余弦函数.函数原型: double tan(double x);函数功能: 计算tan(x)的值,即计算⾓度x的正切数值@函数名称: hypot函数原型: double hypot(double x,double y)函数功能: 已知直⾓三⾓形两个直⾓边长度,求斜边长度函数返回: 斜边长度参数说明: x,y-直⾓边长度所属⽂件: <math.h>#include <stdio.h>#include <math.h>int main(){double result;double x=3.0;double y=4.0;result=hypot(x,y);printf("The hypotenuse is: %lf",result);return 0;}4.反三⾓函数函数原型: double asin(double x);函数功能: 计算sin^-1(x)的值.反正弦值函数函数原型: double acos(double x);函数功能: 计算cos^-1(x)的值,反余弦函数函数原型: double atan(double x);函数功能: 计算tan^-1(x)的值.函数原型: double atan2(double x,double y);函数功能: 计算tan^-1/(x/y)的值.求x/y的反正切值.5.双曲三⾓函数函数原型: double sinh(double x);函数功能: 计算x的双曲正弦函数sinh(x)的值.函数原型: double cosh(double x);函数功能: 计算x的双曲余弦cosh(x)的值.函数原型: double tanh(double x);函数功能: 计算x的双曲正切函数tanh(x)的值.#include <stdio.h>#include <math.h>int main(){double result,x=0.5;result=sin(x);printf("The sin() of %lf is %lf",x,result);return 0;}#include <stdio.h>#include <math.h>int main(){double result;double x=0.5;result=cosh(x);printf("The hyperboic cosine of %lf is %lf",x,result);return 0;}6.指数和对数函数原型: double exp(double x);函数功能: 求e的x次幂函数原型: double fmod(double x,double y);函数功能: 求整数x/y的余数函数原型: double frexp(double val,int *eptr);函数功能: 把双精度数val分解为数字部分(尾数)x和以2为底的指数n,即val=x*2^n,n存放在eptr指向的变量中.函数名称: pow函数原型: double pow(double x,double y);函数功能: 计算以x为底数的y次幂,即计算x^y的值.函数返回: 计算结果参数说明: x-底数,y-幂数所属⽂件: <math.h>使⽤范例:#include <math.h>#include <stdio.h>int main(){double x=2.0,y=3.0;printf("%lf raised to %lf is %lf",x,y,pow(x,y));return 0;}函数原型: double sqrt(double x);函数功能: 计算x的开平⽅.函数返回: 计算结果参数说明: x>=0所属⽂件: <math.h>使⽤范例:#include <math.h>#include <stdio.h>int main(){double x=4.0,result;result=sqrt(x);printf("The square root of %lf is %lf",x,result);return 0;}//log(10) 以 e 为底的 10 的对数;log10(100) 以 10 为底的 100 的对数;如果要算别的对数 log(8) / log(2) 以 2 为底的 8 的对数;如果要计算⾃然常数 e exp(1);//函数原型: double log(double x);函数功能: 求logeX(e指的是以e为底),即计算x的⾃然对数(ln X)函数返回: 计算结果参数说明:所属⽂件: <math.h>使⽤范例:#include <math.h>#include <stdio.h>int main(){double result;double x=8.6872;result=log(x);printf("The natural log of %lf is %lf",x,result);return 0;}函数名称: log10函数原型: double log10(double x);函数功能: 求log10x(10指的是以10为底).计算x的常⽤对数函数返回: 计算结果参数说明:所属⽂件: <math.h>使⽤范例:#include <math.h>#include <stdio.h>int main(){double result;double x=800.6872;result=log10(x);printf("The common log of %lf is %lf",x,result);return 0;}#include <stdio.h>#include <math.h>int main(){double result;double x=4.0;result=exp(x);printf("'e' raised to the power of %lf(e^%lf)=%lf",x,x,result);return 0;}#include <math.h>#include <stdio.h>int main(){double mantissa,number;int exponent;number=8.0;mantissa=frexp(number,&exponent);printf("The number %lf is",number);printf("%lf times two to the",mantissa);printf("power of %d",exponent);return 0;}7.标准化浮点数函数原型:double modf (double x, double *ip);函数功能:将参数的整数部分通过指针回传, 返回⼩数部分,整数部分保存在*ip中函数原型: double ldexp(double x,int exponent)函数功能: 计算x*2的exponent次幂,即2*pow(2,exponent)的数值#include <stdio.h>#include <math.h>int main(){double value;double x=2;value=ldexp(x,3);printf("The ldexp value is: %lf",value);return 0;}8.多项式函数名称: poly函数原型: double poly(double x,int degree,double coeffs[])函数功能: 计算多项式函数返回: 多项式的计算结果参数说明: 计算c[n]*x^n+c[n-1]x^n-1+.....+c[1]*x+c[0]所属⽂件: <math.h>#include <stdio.h>#include <math.h>int main(){double array[]={-1.0,5.0,-2.0,1.0};double result;result=poly(2.0,3,array);printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf",result);return 0;}9.数学错误计算处理@函数名称: matherr函数原型: int matherr(struct exception *e)函数功能: 数学错误计算处理程序函数返回:参数说明: 该函数不能被直接调⽤,⽽是被库函数_matherr()调⽤所属⽂件: <math.h>#include<math.h>int matherr(struct exception *a){return 1;}原⽂:https:///weibo1230123/article/details/81352581。
(一)输入输出常用函数1,printf(1)有符号int%[-][+][0][width][.precision][l][h] d-:左对齐+:正数前加‘+’0:右对齐,acwidth<width,左补零.precision:至少输出位数。
若实际的位数>.precision,按实际输出,否者左边补零(2)无符号int%[-][#][0][width][.precision][l][h] u|o|x|X#:”%o %x/X”输出0,0x,0X.precision:同上,TC/BC包含0x/X,VC下不包含(3)实数输出%[-][+][#][0][width][.precision][l][L] f|e|E|g|G#:必须输出小数点.precision:小数位数(四舍五入)(4)字符和字符串的输出%[-][0][width] c %[-][0][width] [.precision] s.precision:S的前precision位2,scanf%[*][width] [l][h]TypeWith:指定输入数据的宽度,遇空格、Tab、\n结束*:抑制符scanf(“%2d%*2d%3d”,&num1,&num2) 输入123456789\n;num1==12,num2==567.注意:(1)指定width时,读取相应width位,但按需赋值Scanf(“%3c%3c”,&ch1,&ch2)输入a bc d efg ch1==a ch2==d(2)%c 输入单字符时“空格、转义字符”均是有效字符(二)ascll字符/字符串/文件函数1;字符非格式化输入函数(1)int getchar(void) 接受字符,以回车结束,回显(2)int getc(FILE*stream) 从stream中接受字符,以回车结束,回显stream=stdin时,(1)==(2)(3)int getche(void) 直接读取字符,回显conio.h(4)int getchar(void) 直接读取字符,不回显conio.h注意:(1,2)对于回车键返回‘\n’(3,4)对于回车键返回‘\r’2;字符/串非格式化输出函数(1)int putchar(int c) 正常返回字符代码值,出错返回EOF(2)int putc(int c,FILE*stream) 正常返回字符代码值,出错返回EOF stream==stdout(1)=(2)(3)int puts(char*stream) 自动回车换行1;字符串的赋值#include< string.h memory.h >Void *memset (void *s, char ch, unsigned n)将以S为首地址的,一片连续的N个字节内存单元赋值为CH.Void *memcpy ( void *d, void*s, unsigned n)将以S为首地址的一片连续的N个字节内存单元的值拷贝到以D为首地址的一片连续的内存单元中。
C语⾔常见的函数调⽤C语⾔常见的函数调⽤isatty,函数名,主要功能是检查设备类型,判断⽂件描述词是否为终端机。
函数名: isatty⽤法: int isatty(int desc);返回值:如果参数desc所代表的⽂件描述词为⼀终端机则返回1,否则返回0。
程序例:#include <stdio.h>#include <io.h>int main(void){int handle;handle = fileno(stdout);if (isatty(handle))printf("Handle %d is a device type\n", handle);elseprintf("Handle %d isn't a device type\n", handle);re函数名称:fileno(在VC++6.0下为_fileno)函数原型:int _fileno( FILE *stream );函数功能:fileno()⽤来取得参数stream指定的⽂件流所使⽤的返回值:某个数据流的⽂件描述符头⽂件:相关函数:open,fopen,fclosevoid *memset(void *s, int ch, n);函数解释:将s中当前位置后⾯的n个字节(typedef unsigned int size_t )⽤ ch 替换并返回 s 。
memset:作⽤是在⼀段内存块中填充某个给定的值,它是对较⼤的或进⾏清零操作的⼀种最快⽅法函数原型char *fgets(char *buf, int bufsize, FILE *stream);参数*buf: 字符型指针,指向⽤来存储所得数据的地址。
bufsize: 整型数据,指明存储数据的⼤⼩。
*stream: ⽂件结构体指针,将要读取的⽂件流。
返回值1. 成功,则返回第⼀个参数buf;2. 在读字符时遇到end-of-file,则eof指⽰器被设置,如果还没读⼊任何字符就遇到这种情况,则buf保持原来的内容,返回NULL;3. 如果发⽣读⼊错误,error指⽰器被设置,返回NULL,buf的值可能被改变。
功能: 异常终止一个进程用法: void abort(void)函数名: abs功能: 求整数的绝对值用法: int abs(int i)函数名: absread, abswirte功能: 绝对磁盘扇区读、写数据用法: int absread(int drive, int nsects, int sectno, void *buffer) int abswrite(int drive, int nsects, in tsectno, void *buffer函数名: access功能: 确定文件的访问权限用法: int access(const char *filename, int amode)函数名: acos功能:反余弦函数用法: double acos(double x)函数名: allocmem功能: 分配DOS存储段用法:int allocmem(unsigned size, unsigned *seg)函数名: arc功能: 画一弧线用法:void far arc(int x, int y, int stangle, int endangle, int radius)函数名: asctime功能: 转换日期和时间为ASCII码用法:char *asctime(const struct tm *tblock)函数名: asin功能:反正弦函数用法: double asin(double x)函数名: assert功能: 测试一个条件并可能使程序终止用法:void assert(int test)函数名: atan功能: 反正切函数用法: double atan(double x)功能: 计算Y/X的反正切值用法: double atan2(double y, double x)函数名:atexit功能: 注册终止函数用法: int atexit(atexit_t func)函数名: atof功能: 把字符串转换成浮点数用法:double atof(const char *nptr)函数名: atoi功能: 把字符串转换成长整型数用法: int atoi(const char *nptr)函数名: atol功能: 把字符串转换成长整型数用法: long atol(const char *nptr)函数名: bar功能: 画一个二维条形图用法: void far bar(int left, int top, int right, int bottom)函数名: bar3d功能: 画一个三维条形图用法:void far bar3d(int left, int top, int right, int bottom,int depth, int topflag)函数名: bdos功能: DOS系统调用用法: int bdos(int dosfun, unsigned dosdx, unsigned dosal)函数名:bdosptr功能:DOS系统调用用法: int bdosptr(int dosfun, void *argument, unsigned dosal)函数名:bioscom功能: 串行I/O通信用法:int bioscom(int cmd, char abyte, int port)函数名:biosdisk功能: 软硬盘I/O用法:int biosdisk(int cmd, int drive, int head, int track, int sectorint nsects, void *buffer)函数名:biosequip功能: 检查设备用法:int biosequip(void)函数名:bioskey功能: 直接使用BIOS服务的键盘接口用法:int bioskey(int cmd)函数名:biosmemory功能: 返回存储块大小用法:int biosmemory(void)函数名:biosprint功能: 直接使用BIOS服务的打印机I/O用法:int biosprint(int cmd, int byte, int port)函数名:biostime功能: 读取或设置BIOS时间用法: long biostime(int cmd, long newtime)函数名: brk功能: 改变数据段空间分配用法:int brk(void *endds)函数名:bsearch功能: 二分法搜索用法:void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *))函数名: cabs功能: 计算复数的绝对值用法: double cabs(struct complex z);函数名:calloc功能:分配主存储器用法:void *calloc(size_t nelem, size_t elsize);函数名: ceil功能: 向上舍入用法: double ceil(double x);函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str)函数名:chdir功能: 改变工作目录用法: int chdir(const char *path);函数名:_chmod, chmod功能: 改变文件的访问方式用法: int chmod(const char *filename, int permiss);函数名:chsize功能: 改变文件大小用法: int chsize(int handle, long size);函数名: circle功能: 在给定半径以(x, y)为圆心画圆用法: void far circle(int x, int y, int radius);函数名: cleardevice功能: 清除图形屏幕用法: void far cleardevice(void);函数名:clearerr功能: 复位错误标志用法:void clearerr(FILE *stream);函数名: clearviewport功能: 清除图形视区用法: void far clearviewport(void);函数名:_close, close功能: 关闭文件句柄用法:int close(int handle);函数名: clock功能:确定处理器时间用法: clock_t clock(void);函数名:closegraph功能: 关闭图形系统用法: void far closegraph(void);函数名:clreol功能: 在文本窗口中清除字符到行末用法:void clreol(void)函数名:clrscr功能: 清除文本模式窗口用法:void clrscr(void);函数名: coreleft功能: 返回未使用内存的大小用法:unsigned coreleft(void);函数名: cos功能: 余弦函数用法:double cos(double x);函数名:cosh功能: 双曲余弦函数用法: dluble cosh(double x);函数名: country功能: 返回与国家有关的信息用法: struct COUNTRY *country(int countrycode, struct country *country); 函数名: cprintf功能: 送格式化输出至屏幕用法:int cprintf(const char *format[, argument, ...]);函数名: cputs功能: 写字符到屏幕用法: void cputs(const char *string);函数名: _creat creat功能: 创建一个新文件或重写一个已存在的文件用法: int creat (const char *filename, int permiss)函数名:creatnew功能: 创建一个新文件用法:int creatnew(const char *filename, int attrib);函数名: cscanf功能: 从控制台执行格式化输入用法:int cscanf(char *format[,argument, ...]);函数名: ctime功能: 把日期和时间转换为字符串用法:char *ctime(const time_t *time);功能: 设置Ctrl-Break处理程序用法: void ctrlbrk(*fptr)(void);函数名: delay功能: 将程序的执行暂停一段时间(毫秒)用法: void delay(unsigned milliseconds);函数名: delline功能: 在文本窗口中删去一行用法: void delline(void);函数名:detectgraph功能: 通过检测硬件确定图形驱动程序和模式用法: void far detectgraph(int far *graphdriver, int far *graphmode); 函数名: difftime功能: 计算两个时刻之间的时间差用法: double difftime(time_t time2, time_t time1);函数名: disable功能: 屏蔽中断用法:void disable(void);函数名: div功能: 将两个整数相除, 返回商和余数用法:div_t (int number, int denom);函数名: dosexterr功能: 获取扩展DOS错误信息用法:int dosexterr(struct DOSERR *dblkp);函数名: dostounix功能: 转换日期和时间为UNIX时间格式用法: long dostounix(struct date *dateptr, struct time *timeptr);函数名: drawpoly功能: 画多边形用法: void far drawpoly(int numpoints, int far *polypoints);函数名:dup功能: 复制一个文件句柄用法: int dup(int handle);函数名:dup2功能: 复制文件句柄用法: int dup2(int oldhandle, int newhandle);功能: 把一个浮点数转换为字符串用法: char ecvt(double value, int ndigit, int *decpt, int *sign);函数名: ellipse功能: 画一椭圆用法:void far ellipse(int x, int y, int stangle, int endangle,int xradius, int yradius);函数名: enable功能: 开放硬件中断用法: void enable(void);函数名: eof功能: 检测文件结束用法: int eof(int *handle);函数名: exec...功能: 装入并运行其它程序的函数用法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,char *envp[]);int execlp(char *pathname, char *arg0, arg1, .., NULL);int execple(char *pathname, char *arg0, arg1, ..., NULL,char *envp[]);int execv(char *pathname, char *argv[]);int execve(char *pathname, char *argv[], char *envp[]);int execvp(char *pathname, char *argv[]);int execvpe(char *pathname, char *argv[], char *envp[]);函数名:exit功能: 终止程序用法: void exit(int status);函数名: exp功能: 指数函数用法: double exp(double x);函数名: gcvt功能: 把浮点数转换成字符串用法: char *gcvt(double value, int ndigit, char *buf);函数名: geninterrupt功能: 产生一个软中断函数名: getarccoords功能: 取得最后一次调用arc的坐标用法: void far getarccoords(struct arccoordstype far *arccoords); 函数名: getaspectratio功能: 返回当前图形模式的纵横比用法: void far getaspectratio(int far *xasp, int far *yasp);函数名: getbkcolor功能: 返回当前背景颜色用法: int far getbkcolor(void);函数名: getc功能: 从流中取字符用法: int getc(FILE *stream);函数名: getcbrk功能: 获取Control_break设置用法: int getcbrk(void);函数名: getch功能: 从控制台无回显地取一个字符用法: int getch(void);函数名: getchar功能: 从stdin流中读字符用法: int getchar(void);函数名: getche功能: 从控制台取字符(带回显)用法: int getche(void);函数名: getcolor功能: 返回当前画线颜色用法: int far getcolor(void);函数名: getcurdir功能: 取指定驱动器的当前目录用法: int getcurdir(int drive, char *direc);函数名: getcwd功能: 取当前工作目录用法: char *getcwd(char *buf, int n);函数名: getdate功能: 取DOS日期函数名: getdefaultpalette功能: 返回调色板定义结构用法: struct palettetype *far getdefaultpalette(void);函数名: getdisk功能: 取当前磁盘驱动器号用法: int getdisk(void);函数名: getdrivername功能: 返回指向包含当前图形驱动程序名字的字符串指针用法: char *getdrivename(void);函数名: getdta功能: 取磁盘传输地址用法: char far *getdta(void);函数名: getenv功能: 从环境中取字符串用法: char *getenv(char *envvar);函数名: getfat, getfatd功能: 取文件分配表信息用法: void getfat(int drive, struct fatinfo *fatblkp);函数名: getfillpattern功能: 将用户定义的填充模式拷贝到内存中用法: void far getfillpattern(char far *upattern);函数名: getfillsettings功能: 取得有关当前填充模式和填充颜色的信息用法: void far getfillsettings(struct fillsettingstype far *fillinfo); 函数名: getftime功能: 取文件日期和时间用法: int getftime(int handle, struct ftime *ftimep);函数名: getgraphmode功能: 返回当前图形模式用法: int far getgraphmode(void);函数名: getftime功能: 取文件日期和时间用法: int getftime(int handle, struct ftime *ftimep);函数名: getgraphmode功能: 返回当前图形模式用法: int far getgraphmode(void);函数名: getimage功能: 将指定区域的一个位图存到主存中用法: void far getimage(int left, int top, int right, int bottom,void far *bitmap);函数名: getlinesettings功能: 取当前线型、模式和宽度用法: void far getlinesettings(struct linesettingstype far *lininfo): 函数名: getmaxx功能: 返回屏幕的最大x坐标用法: int far getmaxx(void);函数名: getmaxy功能: 返回屏幕的最大y坐标用法: int far getmaxy(void);函数名: getmodename功能: 返回含有指定图形模式名的字符串指针用法: char *far getmodename(int mode_name);函数名: getmoderange功能: 取给定图形驱动程序的模式范围用法: void far getmoderange(int graphdriver, int far *lomode,int far *himode);函数名: getpalette功能: 返回有关当前调色板的信息用法: void far getpalette(struct palettetype far *palette);函数名: getpass功能: 读一个口令用法: char *getpass(char *prompt);函数名: getpixel功能: 取得指定像素的颜色用法: int far getpixel(int x, int y);函数名: gets功能: 从流中取一字符串用法: char *gets(char *string);函数名: gettext功能: 将文本方式屏幕上的文本拷贝到存储区用法: int gettext(int left, int top, int right, int bottom, void *destin);函数名: gettextinfo功能: 取得文本模式的显示信息用法: void gettextinfo(struct text_info *inforec);函数名: gettextsettings功能: 返回有关当前图形文本字体的信息用法: void far gettextsettings(struct textsettingstype far *textinfo); 函数名: gettime功能: 取得系统时间用法: void gettime(struct time *timep);函数名: getvect功能: 取得中断向量入口用法: void interrupt(*getvect(int intr_num));函数名: getverify功能: 返回DOS校验标志状态用法: int getverify(void);函数名: getviewsetting功能: 返回有关当前视区的信息用法: void far getviewsettings(struct viewporttype far *viewport); 函数名: getw功能: 从流中取一整数用法: int getw(FILE *strem);函数名: getx功能: 返回当前图形位置的x坐标用法: int far getx(void);函数名: gety功能: 返回当前图形位置的y坐标用法: int far gety(void);函数名: gmtime功能: 把日期和时间转换为格林尼治标准时间(GMT)用法: struct tm *gmtime(long *clock);函数名: gotoxy功能: 在文本窗口中设置光标用法: void gotoxy(int x, int y);函数名: gotoxy功能: 在文本窗口中设置光标用法: void gotoxy(int x, int y);函数名: graphdefaults功能: 将所有图形设置复位为它们的缺省值用法: void far graphdefaults(void);函数名: grapherrormsg功能: 返回一个错误信息串的指针用法: char *far grapherrormsg(int errorcode);函数名: graphresult功能: 返回最后一次不成功的图形操作的错误代码用法: int far graphresult(void);函数名: _graphfreemem功能: 用户可修改的图形存储区释放函数用法: void far _graphfreemem(void far *ptr, unsigned size);函数名: _graphgetmem功能: 用户可修改的图形存储区分配函数用法: void far *far _graphgetmem(unsigned size);函数名: harderr功能: 建立一个硬件错误处理程序用法: void harderr(int (*fptr)());函数名: hardresume功能: 硬件错误处理函数用法: void hardresume(int rescode);函数名: highvideo功能: 选择高亮度文本字符用法: void highvideo(void);函数名: hypot功能: 计算直角三角形的斜边长用法: double hypot(double x, double y);函数名: imagesize功能: 返回保存位图像所需的字节数用法: unsigned far imagesize(int left, int top, int right, int bottom); 函数名: initgraph功能: 初始化图形系统用法: void far initgraph(int far *graphdriver, int far *graphmode函数名: inport功能: 从硬件端口中输入用法: int inp(int protid);函数名: insline功能: 在文本窗口中插入一个空行用法: void insline(void);函数名: installuserdriver功能: 安装设备驱动程序到BGI设备驱动程序表中用法: int far installuserdriver(char far *name, int (*detect)(void));函数名: installuserfont功能: 安装未嵌入BGI系统的字体文件(CHR)用法: int far installuserfont(char far *name);函数名: int86功能: 通用8086软中断接口用法: int int86(int intr_num, union REGS *inregs, union REGS *outregs) 函数名: int86x功能: 通用8086软中断接口用法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, 函数名: intdos功能: 通用DOS接口用法: int intdos(union REGS *inregs, union REGS *outregs);函数名: intdosx功能: 通用DOS中断接口用法: int intdosx(union REGS *inregs, union REGS *outregs,struct SREGS *segregs);函数名: intr功能: 改变软中断接口用法: void intr(int intr_num, struct REGPACK *preg);函数名: ioctl功能: 控制I/O设备用法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);函数名: isatty功能: 检查设备类型用法: int isatty(int handle);函数名: itoa功能: 把一整数转换为字符串用法: char *itoa(int value, char *string, int radix);函数名: kbhit功能: 检查当前按下的键用法: int kbhit(void);函数名: keep功能: 退出并继续驻留用法: void keep(int status, int size);函数名: kbhit功能: 检查当前按下的键用法: int kbhit(void);函数名: keep功能: 退出并继续驻留用法: void keep(int status, int size);函数名: labs用法: long labs(long n);函数名: ldexp功能: 计算value*2的幂用法: double ldexp(double value, int exp);函数名: ldiv功能: 两个长整型数相除, 返回商和余数用法: ldiv_t ldiv(long lnumer, long ldenom);函数名: lfind功能: 执行线性搜索用法: void *lfind(void *key, void *base, int *nelem, int width,int (*fcmp)());函数名: line功能: 在指定两点间画一直线用法: void far line(int x0, int y0, int x1, int y1);函数名: linerel功能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线用法: void far linerel(int dx, int dy);函数名: localtime功能: 把日期和时间转变为结构用法: struct tm *localtime(long *clock);函数名: lock功能: 设置文件共享锁用法: int lock(int handle, long offset, long length);函数名: log功能: 对数函数ln(x)用法: double log(double x);函数名: log10功能: 对数函数log用法: double log10(double x);函数名: longjump功能: 执行非局部转移用法: void longjump(jmp_buf env, int val);函数名: lowvideo功能: 选择低亮度字符用法: void lowvideo(void);函数名: lrotl, _lrotl功能: 将无符号长整型数向左循环移位用法: unsigned long lrotl(unsigned long lvalue, int count);unsigned long _lrotl(unsigned long lvalue, int count);函数名: lsearch功能: 线性搜索用法: void *lsearch(const void *key, void *base, size_t *nelem,size_t width, int (*fcmp)(const void *, const void *));函数名: lseek功能: 移动文件读/写指针用法: long lseek(int handle, long offset, int fromwhere);main()主函数每一C 程序都必须有一main() 函数, 可以根据自己的爱好把它放在程序的某个地方。
C语言函数大全(p开头)函数名: parsfnm功能: 分析文件名用法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option);程序例:#include#include#include#includeint main(void){char line[80];struct fcb blk;/* get file name */printf("Enter drive and file name (no path - ie. a:file.dat)\n"); gets(line);/* put file name in fcb */if (parsfnm(line, &blk, 1) == NULL)printf("Error in parsfm call\n");elseprintf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name); return 0;}函数名: peek功能: 检查存储单元用法: int peek(int segment, unsigned offset);程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n");value = peek(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf("Right shift off\n");if (value & 2)printf("Left shift on\n");elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n");elseprintf("Control key off\n");if (value & 8)printf("Alt key on\n");elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n");elseprintf("Scroll lock off\n");if (value & 32)printf("Num lock on\n");elseprintf("Num lock off\n");if (value & 64)printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: peekb功能: 检查存储单元用法: char peekb (int segment, unsigned offset);程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n"); value = peekb(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf("Right shift off\n");if (value & 2)printf("Left shift on\n");elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n");elseprintf("Control key off\n");if (value & 8)printf("Alt key on\n");elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n");elseprintf("Scroll lock off\n");if (value & 32)printf("Num lock on\n");elseprintf("Num lock off\n");if (value & 64)printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: perror功能: 系统错误信息用法: void perror(char *string);程序例:#includeint main(void){FILE *fp;fp = fopen("perror.dat", "r");if (!fp)perror("Unable to open file for reading");return 0;}函数名: pieslice功能: 绘制并填充一个扇形用法: void far pieslice(int x, int stanle, int endangle, int radius);#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int stangle = 45, endangle = 135, radius = 100;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{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;/* set fill style and draw a pie slice */setfillstyle(EMPTY_FILL, getmaxcolor());pieslice(midx, midy, stangle, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: poke功能: 存值到一个给定存储单元用法: void poke(int segment, int offset, int value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n");poke(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: pokeb功能: 存值到一个给定存储单元用法: void pokeb(int segment, int offset, char value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n"); getch();pokeb(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: poly功能: 根据参数产生一个多项式用法: double poly(double x, int n, double c[]);程序例:#include#include/* polynomial: x**3 - 2x**2 + 5x - 1 */int main(void){double array[] = { -1.0, 5.0, -2.0, 1.0 };double result;result = poly(2.0, 3, array);printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n", result);return 0;}函数名: pow功能: 指数函数(x的y次方)用法: double pow(double x, double y);程序例:#includeint main(void){double x = 2.0, y = 3.0;printf("%lf raised to %lf is %lf\n", x, y, pow(x, y)); return 0;}函数名: pow10功能: 指数函数(10的p次方)用法: double pow10(int p);程序例:#include#includeint main(void){double p = 3.0;printf("Ten raised to %lf is %lf\n", p, pow10(p)); return 0;}函数名: printf功能: 产生格式化输出的函数用法: int printf(char *format...);程序例:#include#include#define I 555#define R 5.5int main(void){int i,j,k,l;char buf[7];char *prefix = buf;char tp[20];printf("prefix 6d 6o 8x 10.2e ""10.2f\n");strcpy(prefix,"%");for (i = 0; i < 2; i++){for (j = 0; j < 2; j++)for (k = 0; k < 2; k++)for (l = 0; l < 2; l++){if (i==0) strcat(prefix,"-");if (j==0) strcat(prefix,"+");if (k==0) strcat(prefix,"#");if (l==0) strcat(prefix,"0");printf("%5s |",prefix);strcpy(tp,prefix);strcat(tp,"6d |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"6o |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"8x |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"10.2e |");printf(tp,R);strcpy(tp,prefix);strcat(tp,"10.2f |");printf(tp,R);printf(" \n");strcpy(prefix,"%");}}return 0;}函数名: putc功能: 输出一字符到指定流中用法: int putc(int ch, FILE *stream);程序例:#includeint main(void){char msg[] = "Hello world\n";int i = 0;while (msg[i])putc(msg[i++], stdout);return 0;函数名: putch功能: 输出字符到控制台用法: int putch(int ch);程序例:#include#includeint main(void){char ch = 0;printf("Input a string:");while ((ch != '\r')){ch = getch();putch(ch);}return 0;}函数名: putchar功能: 在stdout上输出字符用法: int putchar(int ch);程序例:#include/* define some box-drawing characters */ #define LEFT_TOP 0xDA#define RIGHT_TOP 0xBF#define HORIZ 0xC4#define VERT 0xB3#define LEFT_BOT 0xC0#define RIGHT_BOT 0xD9int main(void){char i, j;/* draw the top of the box */putchar(LEFT_TOP);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_TOP);putchar('\n');/* draw the middle */for (i=0; i<4; i++)putchar(VERT);for (j=0; j<10; j++)putchar(' ');putchar(VERT);putchar('\n');}QQ291911320/* draw the bottom */putchar(LEFT_BOT);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_BOT);putchar('\n');return 0;}函数名: putenv功能: 把字符串加到当前环境中用法: int putenv(char *envvar);程序例:#include#include#include#include#includeint main(void){char *path, *ptr;int i = 0;/* get the current path environment */ptr = getenv("PATH");/* set up new path */path = malloc(strlen(ptr)+15);strcpy(path,"PATH=");strcat(path,ptr);strcat(path,";c:\\temp");/* replace the current path and display current environment */ putenv(path);while (environ[i])printf("%s\n",environ[i++]);return 0;}函数名: putimage功能: 在屏幕上输出一个位图用法: void far putimage(int x, int y, void far *bitmap, int op);程序例:#include#include#include#include#define ARROW_SIZE 10void draw_arrow(int x, int y);int main(void){/* request autodetection */int gdriver = DETECT, gmode, errorcode;void *arrow;int x, y, maxx;unsigned int size;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx();x = 0;y = getmaxy() / 2;/* draw the image to be grabbed */draw_arrow(x, y);/* calculate the size of the image */size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE); /* allocate memory to hold the image */arrow = malloc(size);/* grab the image */getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow); /* repeat until a key is pressed */while (!kbhit()){/* erase old image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);x += ARROW_SIZE;if (x >= maxx)x = 0;/* plot new image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);}/* clean up */free(arrow);closegraph();return 0;}void draw_arrow(int x, int y){/* draw an arrow on the screen */moveto(x, y);linerel(4*ARROW_SIZE, 0);linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);linerel(0, 2*ARROW_SIZE);linerel(2*ARROW_SIZE, -1*ARROW_SIZE);}函数名: putpixel功能: 在指定位置画一像素用法: void far putpixel (int x, int y, int pixelcolor);程序例:#include#include#include#include#include#define PIXEL_COUNT 1000#define DELAY_TIME 100 /* in milliseconds */int main(void){/* request autodetection */int gdriver = DETECT, gmode, errorcode;int i, x, y, color, maxx, maxy, maxcolor, seed;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx() + 1;maxy = getmaxy() + 1;maxcolor = getmaxcolor() + 1;while (!kbhit()){/* seed the random number generator */seed = random(32767);srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor);putpixel(x, y, color);}delay(DELAY_TIME);srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor);if (color == getpixel(x, y))putpixel(x, y, 0);}}/* clean up */getch();closegraph();return 0;}函数名: puts功能: 送一字符串到流中用法: int puts(char *string);程序例:#includeint main(void){char string[] = "This is an example output string\n";puts(string);return 0;}函数名: puttext功能: 将文本从存储区拷贝到屏幕用法: int puttext(int left, int top, int right, int bottom, void *source);程序例:#includeint main(void){char buffer[512];/* put some text to the console */clrscr();gotoxy(20, 12);cprintf("This is a test. Press any key to continue ...");getch();/* grab screen contents */gettext(20, 12, 36, 21,buffer);clrscr();/* put selected characters back to the screen */gotoxy(20, 12);puttext(20, 12, 36, 21, buffer);getch();return 0;}函数名: putw功能: 把一字符或字送到流中用法: int putw(int w, FILE *stream);程序例:#include#include#define FNAME "test.$$$"int main(void){FILE *fp;int word;/* place the word in a file */fp = fopen(FNAME, "wb");if (fp == NULL){printf("Error opening file %s\n", FNAME);exit(1);}word = 94;putw(word,fp);if (ferror(fp))printf("Error writing to file\n");elseprintf("Successful write\n");fclose(fp);/* reopen the file */fp = fopen(FNAME, "rb");if (fp == NULL){printf("Error opening file %s\n", FNAME);exit(1);}/* extract the word */word = getw(fp);if (ferror(fp))printf("Error reading file\n");elseprintf("Successful read: word = %d\n", word); /* clean up */fclose(fp);unlink(FNAME);return 0;}。
(一)输入输出常用函数1,printf(1)有符号int%[-][+][0][width][.precision][l][h] d-:左对齐+:正数前加‘+’0:右对齐,acwidth<width,左补零.precision:至少输出位数。
若实际的位数>.precision,按实际输出,否者左边补零(2)无符号int%[-][#][0][width][.precision][l][h] u|o|x|X#:”%o %x/X”输出0,0x,0X.precision:同上,TC/BC包含0x/X,VC下不包含(3)实数输出%[-][+][#][0][width][.precision][l][L] f|e|E|g|G#:必须输出小数点.precision:小数位数(四舍五入)(4)字符和字符串的输出%[-][0][width] c %[-][0][width] [.precision] s.precision:S的前precision位2,scanf%[*][width] [l][h]TypeWith:指定输入数据的宽度,遇空格、Tab、\n结束*:抑制符scanf(“%2d%*2d%3d”,&num1,&num2) 输入123456789\n;num1==12,num2==567.注意:(1)指定width时,读取相应width位,但按需赋值Scanf(“%3c%3c”,&ch1,&ch2)输入a bc d efg ch1==a ch2==d(2)%c 输入单字符时“空格、转义字符”均是有效字符(二)ascll字符/字符串/文件函数1;字符非格式化输入函数(1)int getchar(void) 接受字符,以回车结束,回显(2)int getc(FILE*stream) 从stream中接受字符,以回车结束,回显stream=stdin时,(1)==(2)(3)int getche(void) 直接读取字符,回显conio.h(4)int getchar(void) 直接读取字符,不回显conio.h注意:(1,2)对于回车键返回‘\n’(3,4)对于回车键返回‘\r’2;字符/串非格式化输出函数(1)int putchar(int c) 正常返回字符代码值,出错返回EOF(2)int putc(int c,FILE*stream) 正常返回字符代码值,出错返回EOF stream==stdout(1)=(2)(3)int puts(char*stream) 自动回车换行1;字符串的赋值#include< string.h memory.h >Void *memset (void *s, char ch, unsigned n)将以S为首地址的,一片连续的N个字节内存单元赋值为CH.Void *memcpy ( void *d, void*s, unsigned n)将以S为首地址的一片连续的N个字节内存单元的值拷贝到以D为首地址的一片连续的内存单元中。
c语言标准库中的函数名
C语言标准库中的函数名
C语言标准库是C语言程序设计中不可或缺的一部分,它包含了大量的函数,可以用于各种不同的操作。
以下是C语言标准库中常用的函数名:
1. 字符串处理函数
- strcpy:将一个字符串复制到另一个字符串中
- strcat:将一个字符串连接到另一个字符串的末尾
- strlen:计算一个字符串的长度
- strcmp:比较两个字符串是否相等
- strchr:在一个字符串中查找某个字符第一次出现的位置
2. 数学函数
- abs:返回一个整数的绝对值
- sqrt:返回一个浮点数的平方根
- pow:求幂运算
- sin/cos/tan:三角函数
3. 文件操作函数
- fopen/fclose:打开/关闭文件
- fread/fwrite:读取/写入文件数据
- fseek/ftell:移动文件指针/获取当前指针位置
4. 内存操作函数
- malloc/free:动态分配/释放内存空间
- memset/memcpy:设置/复制内存内容
5. 时间日期函数
- time:获取当前时间戳
- localtime/gmtime:将时间戳转换为本地时间/协调世界时(UTC)时间格式
- strftime:格式化输出时间日期信息
以上是C语言标准库中常用的一些函数名,当然还有很多其他的函数,需要根据具体需求选择使用。
在编写C语言程序时,熟练掌握这些函
数的用法可以提高编程效率和代码质量。
合用标准文案C 库函数1. 数学函数头文件为 #include<math.h>也许 #include"math.h"函数名函数原型功能返回值说明absint abs(int x)求整数 x 的绝对值计算结果double acos(doubleX 应在-1 到1范围acos计算 cos -1 (x) 的值计算结果x)内X 应在-1 到1范围asindouble asin(double x)计算 sin -1 (x) 的值计算结果内atan double atan(double x) 计算 tan -1 (x) 的值计算结果double atan2(doubleAtan2计算 tan -1 (x/y) 的值计算结果x,double y)cos double cos(double x) 计算 cos(x) 的值 计算结果 X 的单位为弧度double cosh(double计算 x 的双曲余弦cosh计算结果x)函数 cosh(x) 的值exp double exp(double x) 求 e x的值 计算结果 fabsdouble fabs(double x)求 x 的绝对值计算结果该整数的double floor(double求出不大于 x 的最floor双精度实x)大整数数fmod double fmod(double 求整除 x/y 的余数 返回余数合用标准文案x,double y) double frexp(double的双精度实数把双精度数val 分解为数字局部(尾数 )x返回数字和以 2 为底的指数frexpval, int *eptr)n ,即 val=x*2局部 xn0.5 ≤x< 1log double log(double x)double log10(double log10x)Double modf(double modfval, double *iptr)double pow(double powx,double y) rand Int rand(void)n 存放在eptr指向的变量中求 log ex,即 ln x计算结果求 log10x计算结果把双精度数val 分解为整数局部和小数Val 的小数局部,把整数局部存局部到 iptr计算xy的值计算结果产生随机 -90 到32767间的随机整随机整数数sin Double sin(double x)计算sin x的值计算结果X 单位为弧度sinh double sinh(double x)计算x的双曲正弦计算结果函数 sinh(x) 的值sqrt Double sqrt(double x)计算x计算结果X 应≥0 tan Double tan(double x)计算tan(x)的值计算结果X 单位为弧度Double tanh(double计算x的双曲正切tanh计算结果x)函数 tanh(x) 的值2.字符函数和字符串函数函数名函数原型功能返回值包括文件检查 ch 是否是字母isalnu Int isalnum (int是字母或数字返(alpha) 或数字m ch);回 1 ;否那么返回 0(numeric)是,返回 1 ;不是,isalpha Int isalpha(int ch);检查 ch 可否字母那么返回 0检查 ch 可否控制字符是,返回 1 ;不是,iscntrl Int iscntrl (int ch);〔其 ASCII 码在 0 和那么返回 00x1F 之间〕检查 ch 可否为数字是,返回 1 ;不是,isdigit Int isdigit (int ch);〔0~9 〕那么返回 0检查 ch 可否可打印字符Int isgraph (int是,返回 1 ;不是,isgraph〔其 ASCII 码在 0x21 和ch);那么返回 00x7E 之间〕,不包括空格Int islower (int检查 ch 可否小写字母是,返回 1 ;不是,islowerch);〔 a~z 〕那么返回 0检查 ch 可否可打印字符,〔包括空格〕,其是,返回 1 ;不是,isprint Intisprint (int ch);ASCII 码在 0x20 和 0x7E那么返回 0之间,ispunct Int ispunct (int检查 ch 可否标点字符是,返回 1 ;不是,ch);〔不包括空格〕,即除字那么返回0母、数字和空格以外的所有可打印字符Int isspace (int检查ch可否空格符、跳是,返回1;不是,isspacech);格符〔制表符〕或换行符那么返回0Int isupper (int检查ch可否大写字母是,返回1;不是,isupperch);〔A~Z 〕那么返回0检查 ch 可否一个十六进Intisxdigit (int是,返回1;不是,isxdigit制数字字符〔即0~9 ,ch);那么返回 0或 A~F ,或 a~f 〕把字符串str2 接到 str1char *strcat(charstrcat后边,str1 最后边的’ \0 ’Str1 *str1,char *str2);被取消找出 str 指向的字符串中返回指向该地址char *strchr(charstrchr第一次出现字符ch 的位的指针,如找不*str,int ch);置到,那么返回空指针Str1 <str2 ,返回负数;char *strcmp(char比较两个字符串str1 、Str1 =str2 ,返回strcmp*str1,char *str2);str20 ;str1 > str2 ,返回正数。
c语言的数组函数名C语言的数组函数名在C语言中,数组是一种非常常见且重要的数据结构,它可以存储多个相同类型的元素。
为了方便操作和处理数组,C语言提供了许多数组函数,这些函数可以对数组进行不同的操作,如初始化、赋值、排序、查找等。
本文将介绍几个常用的数组函数名,并对它们的用法进行详细讲解。
一、数组初始化函数——memsetmemset是C语言中非常常用的一个数组初始化函数,它可以将数组的每个元素都设置为指定的值。
函数的声明如下:void *memset(void *s, int c, size_t n);其中,s表示要初始化的数组,c表示要设置的值,n表示要初始化的字节数。
该函数的返回值为指向数组s的指针。
例如,我们可以使用memset函数将一个整型数组中的所有元素都设置为0,代码如下:int arr[10];memset(arr, 0, sizeof(arr));二、数组复制函数——memcpymemcpy是C语言中用于数组复制的函数,它可以将一个数组的内容复制到另一个数组中。
函数的声明如下:void *memcpy(void *dest, const void *src, size_t n);其中,dest表示目标数组,src表示源数组,n表示要复制的字节数。
该函数的返回值为指向目标数组dest的指针。
例如,我们可以使用memcpy函数将一个整型数组复制到另一个数组中,代码如下:int src[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};int dest[10];memcpy(dest, src, sizeof(src));三、数组排序函数——qsortqsort是C语言中用于数组排序的函数,它可以对数组的元素进行升序或降序排序。
函数的声明如下:void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));其中,base表示要排序的数组,nmemb表示数组中元素的个数,size表示每个元素的大小,compar表示用于比较元素的函数。
C语言函数大全函数名:abort功能:异常终止一个进程用法:void abort(void)函数名:abs功能:求整数的绝对值用法:int abs(int i)函数名:absread。
abswirte功能:绝对磁盘扇区读、写数据用法:int absread(int drive。
int nsects。
int sectno。
void *buffer)int abswrite(int drive。
int nsects。
in tsectno。
void *buffer函数名:access功能:确定文件的访问权限用法:int access(const char *filename。
int amode)函数名:acos功能:反余弦函数用法:double acos(double x)函数名:allocmem功能:分配DOS存储段用法:int allocmem(unsigned size。
unsigned *seg)函数名:arc功能:画一弧线用法:void far arc(int x。
int y。
int stangle。
int endangle。
int radius)函数名:asctime功用:转换日期和工夫为ASCII码用法:char *asctime(const struct tm *tblock)函数名:asin功用:归正弦函数用法:double asin(double x)函数名:assert功能:测试一个条件并可能使程序终止用法:void assert(int test)函数名:XXX功用:归正切函数用法:double atan(double x)函数名:atan2功用:计较Y/X的归正切值用法:double atan2(double y。
double x)函数名:atexit功能:注册终止函数用法:int atexit(atexit_t func)函数名:atof功用:把字符串转换成浮点数用法:double atof(const char *nptr)函数名:atoi功用:把字符串转换发展整型数用法:int atoi(const char *nptr)函数名:atol功用:把字符串转换发展整型数用法:long atol(const char *nptr)函数名:bar功用:画一个二维条形图用法:void far bar(int left。
C语言函数大全(部分)1.分类函数,所在函数库为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值,否则返回0int 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')2 数学函数,所在函数库为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+y2 double 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转换成双精度数,并返回这个数,错误返回0 int atoi(char *nptr) 将字符串nptr转换成整型数,并返回这个数,错误返回0 long 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()返回浮点状态字3 目录函数, 所在函数库为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变量,未找到文件返回NULL4 进程函数,所在函数库为stdlib.h、process.hvoid abort() 此函数通过调用具有出口代码3的_exit写一个终止信息于stderr,并异常终止程序。
c语言函数三要素C语言函数三要素C语言函数是程序中的基本组成单元,它由三个要素构成:函数名、参数列表和返回值类型。
下面将分别介绍这三个要素。
一、函数名函数名是C语言函数的标识符,用于唯一标识一个函数。
在定义一个函数时,必须给它取一个唯一的名字。
函数名应该具有描述性,能够清楚地表达出该函数所完成的任务。
在C语言中,函数名可以由字母、数字和下划线组成,但必须以字母或下划线开头。
同时,C语言对大小写敏感,因此大写字母和小写字母被视为不同的字符。
二、参数列表参数列表是指在调用一个函数时传递给该函数的数据。
参数列表可以为空,也可以包含多个参数。
每个参数由其类型和名称组成。
在定义一个函数时,需要指定其所需的参数类型和数量,并为每个参数指定一个名称。
在C语言中,参数类型可以是任何基本数据类型(如int、float等)或用户自定义数据类型(如结构体)。
同时,在定义一个函数时也可以使用省略号表示可变数量的参数。
三、返回值类型返回值类型指定了该函数执行完毕后所返回的数据类型。
如果该函数不需要返回任何数据,则返回值类型应该为void。
在C语言中,返回值类型可以是任何基本数据类型或用户自定义数据类型。
如果函数需要返回多个值,则可以使用结构体或指针作为返回值类型。
综上所述,C语言函数的三要素分别是函数名、参数列表和返回值类型。
在定义一个函数时,需要明确指定这三个要素,并保证它们的正确性和合理性。
下面给出一个示例代码,以说明如何定义一个C语言函数。
示例代码:#include <stdio.h>/* 定义一个求和函数 */int sum(int a, int b){return a + b;}int main(){int x = 10, y = 20;int result = sum(x, y);printf("The sum of %d and %d is %d\n", x, y, result);return 0;}在上述示例代码中,我们定义了一个名为sum的函数,该函数接受两个整数参数a和b,并返回它们的和。