C语言中函数名
C语言math.h中常用函数

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。
C语言中的常用函数

函数名: fscanf
功 能: 从一个流中执行格式化输入
用 法: int fscanf(FILE *stream, char *format[,argument...]);
函数名: setbkcolor
功 能: 用调色板设置当前背景颜色
用 法: void far setbkcolor(int color);
函数名: setcolor
功 能: 设置当前画线颜色
用 法: void far setcolor(int color);
sqrt 函数
函数名: sqrt
功 能: 计算平方根
用 法: double sqrt(double x);
strcat 函数
? %-m.ns,n个字符输出在m列范围内的左侧,右补空格。如果n>m,则m自动取n的值。
⑦f格式说明。f格式用来输出带小数点的单、双精度实数。
? %f不指定字段宽度,单精度有效数字位数一般为7位。有6位小数位。
? %m.nf 指定输出的数值共占m位,其中有n位小数。
?%-m.nf与%m.nf基本相同,只是使输出数值向左端靠,右端补空格。
函数名: fopen
功 能: 打开一个流
用 法: FILE *fopen(char *filename, char *type);
函数名: fprintf
功 能: 传送格式化输出到一个流中
用 法: int fprintf(FILE *stream, char *format[, argument,...]);
函数名: strcat
功 能: 字符串拼接函数
用 法: char *strcat(char *destin, char *source);
C语言~所有的字符串操作函数

7.函数名: strcspn 功 能: 在串中查找第一个给定字符集内容的段 用 法: int strcspn(char *str1, char *str2); 程序例: #i nclude <stdio.h> #i nclude <string.h> #i nclude <alloc.h> int main(void) { char *string1 = "1234567890"; char *string2 = "747DC8"; int length;
printf("buffer 2 is greater than buffer 1\n"); if (ptr < 0)
printf("buffer 2 is less than buffer 1\n"); if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); return 0; }
printf("buffer 2 is less than buffer 1\n"); if (ptr == 0)
printf("buffer 2 equals buffer 1\n"); return 0; }
14.函数名: strncpy 功 能: 串拷贝 用 法: char *strncpy(char *destin, char *source, int maxlen); 程序例: #i nclude <stdio.h> #i nclude <string.h> int main(void) {
C语言中常用函数大全

(一)输入输出常用函数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语言scanf 函数

int main()
{
char str[80];
char str1[80];
char str2[80];
scanf("%s",str);/*此处输入:I love you! */
printf("%s",str);
%n 至此已读入值的等价字符数
%[] 扫描字符集合
%% 读%符号
附加格式说明字符表
修饰符 说明
L/l 长度修饰符 输入"长"数据
#include &l{
int i;
char j;
for(i = 0;i < 10;i++)
{
scanf(" %c",&j);/*注意这里%前有个空格*/
}
}
可以运行看看两个程序有什么不同。
return 0;
}
问题三:键盘缓冲区残余信息问题
#include <stdio.h>
int main()
{
int a;
char c;
do
{
scanf("%d",&a);
scanf("%c",&c);
scanf("%c",&c);
fflush(stdin);
printf("a=%d c=%c/n",a,c);
}while(c!='N');
}
这里再给一个用“空格符”来处理缓冲区残余信息的示例:
C语言常见的函数调用

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的值可能被改变。
(完整版)C语言函数大全

功能: 异常终止一个进程用法: 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开头-完整版

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、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
strtok()
字符串分割函数
strstr()
字符串查找函数
strspn()
字符查找函数
strrchr()
定位字符串中最后出现的指定字符
strpbrk()
定位字符串中第一个出现的指定字符
strncpy()
复制字符串
strncat()
字符串连接函数
abs()
求绝对值函数(适合整数求绝对值)
六、文件操作函数
ungetc()
写文件函数(将指定字符写回文件流中)
setvbuf()
设置文件流的缓冲区
setlinebuf()
设置文件流为线性缓冲区
setbuffer()
设置文件流的缓冲区
setbuf()
设置文件流的缓冲区
rewind()
重设文件流的读写位置为文件开头
一、字符测试函数(#include<ctype.h>) 2页
二、字符串操作函数(#include<string.h>) 14页
三、内存管理函数34页
四、日期时间函数47页
五、数学函数54页
六、文件操作函数64页
七、进程操作函数119页
八、文件权限控制函数144页
九、信号处理函数174页
十、接口处理函数189页
十一、环境变量函数207页
十二、终端控制函数209页
一、字符测试函数(#include<ctype.h>)
isupper()
测试字符是否为大写英文字
ispunct()
测试字符是否为标点符号或特殊符号
isspace()
测试字符是否为空格字符
isprint()
测试字符是否为可打印字符
islower()
测试字符是否为小写字母
三、内存管理函数
memset()
内存填入函数(将内存空间填入某值)
memmove()
内存复制函数
memcpy()
内存复制函数(复制内存内容)
memcmp()
内存比较函数
memchr()
在内存中查找特定字符
memccpy()
复制内存中的内容
bzero()
内存管理函数(将一段内存清零)
bcopy()
复制内存内容
tan()
正切函数
sqrt()
开方函数(取平方根值)
sinh()
正弦函数(取双曲线正玄函数值)
sin()
正弦函数
pow()
求次方函数(求一个数的N次方)
log10()
对数函数(求以10为底的对数值)
log()
对数函数(求以e为底的对数值)
ldexp()
次方函数(计算2的N次方的值)
frexp()
将浮点型数分为底数与指数
清除文件流的错误旗标
write()
putchar()
字符输出函数(将指定的字符写到标准输出设备)
putc()
写文件函数(将一指定字符写入文件中)
mktemp()
产生唯一临时文件名
gets()
字符输入函数(由标准输入设备内读进一字符串)
getchar()
字符输入函数(由标准输入设备内读进一字符)
getc()
读文件函数(由文件中读取一个字符)
fopen()
文件打开函数(结果为文件句柄)
fileno()
获取文件流所使用的文件描述词
fgets()
读取文件字符串
fgetc()
读文件函数(由文件中读取一个字符)
fflush()
更新缓冲区
feof()
检查文件流是否读到了文件尾
fdopen()
将文件描述词转为文件指针
fclose()
关闭打开的文件
clearerr()
exp()
指数函数
cosh()
余弦函数(取双曲线余玄函数值)
cos()
余弦函数(取余玄函数值)
ceil()
取整函数(取不小于参数的最小整型数)
atan2()
反正切函数(取得反正切函数值)
atan()
反正切函数(取反正切函数值)
asin()
反正弦函数(取反正弦函数值)
acos()
反余弦函数(取反余弦函数数值)
fwrite()
写文件函数(将数据流写入文件中)
ftell()
取得文件流的读取位置
fseek()
移动文件流的读写位置
freopen()
打开文件函数,并获得文件句柄
fread()
读文件函数(从文件流读取数据)
fputs()
写文件函数(将一指定的字符串写入文件内)
fputc()
写文件函数(将一指定字符写入文件流中)
strncasecmp()
字符串比较函数(忽略大小写)
strlen()
字符串长度计算函数
strdup()
复制字符串
strcspn()
查找字符串
strcpy()
复制字符串
strcoll()
字符串比较函数(按字符排列次序)
strcmp()
字符串比较ቤተ መጻሕፍቲ ባይዱ数(比较字符串)
strchr()
字符串查找函数(返回首次出现字符的位置)
将整数转换成合法的ASCII码字符
strtoul()
将字符串转换成无符号长整型数
strtol()
将字符串转换成长整型数
strtod()
将字符串转换成浮点数
gcvt()
将浮点型数转换为字符串(四舍五入)
atol()
将字符串转换成长整型数
atoi()
将字符串转换成整型数
atof()
将字符串转换成浮点型数
bcmp()
内存操作函数(比较内存内容)
munmap()
解除内存映射
mmap()
建立内存映射
malloc()
分配一段内存空间
getpagesize()
取得内存分页大小
free()
释放内存空间
calloc()
配置内存空间
四、日期时间函数
time()
取得本地时间(日期时间函数)
settimeofday()
设置当前时间戳
mktime()
将时间结构数据转换成经过的秒数
localtime()
获取当地目前时间和日期
gmtime()
获取当前时间和日期
gettimeofday()
获取当前时间
ctime()
将时间和日期以字符串格式表示
asctime()
将时间日期以字符串格式表示
五、数学函数
tanh()
正切函数(取双曲线正切函数值)
strcat()
连接字符串
strcasecmp()
字符串比较函数(忽略大小写比较字符串)
rindex()
字符串查找函数(返回最后一次出现的位置)
index()
字符串查找函数(返回首次出现的位置)
toupper()
字符串转换函数(小写转大写)
tolower()
字符串转换函数(大写转小写)
toascii()
isgraphis()
测试字符是否为可打印字符
isdigit()
测试字符是否为阿拉伯数字
iscntrl()
测试字符是否为ASCII码的控制字符
isascii()
测试字符是否为ASCII码字符
isalpha()
测试字符是否为英文字母
isalnum()
测试字符是否为英文或数字
isxdigit()
测试字符是否为16进制数字