C语言函数大全

合集下载

C语言常用函数

C语言常用函数

C语言的常用库函数函数1。

absread()读磁盘绝对扇区函数原形:int absread(int drive,int num,int sectnum,void *buf)功能:从drive指定的驱动器磁盘上,sectnum指定的逻辑扇区号开始读取(通过DOS中断0x25读取)num 个(最多64K个)扇区的内容,储存于buf所指的缓冲区中。

参数:drive=0对应A盘,drive=1对应B盘。

返回值:0:成功;-1:失败。

头文件:dos.h函数2。

abswrite()写磁盘绝对扇区函数原形:int abswrite(int drive,int nsects,int lsect,void *buffer)drive=0(A驱动器)、1(B驱动器)、nsects=要写的扇区数(最多64K个);lsect=起始逻辑扇区号;buffer=要写入数据的内存起始地址。

功能:将指定内容写入(调用DOS中断0x26)磁盘上的指定扇区,即使写入的地方是磁盘的逻辑结构、文件、FAT表和目录结构所在的扇区,也照常进行。

返回值:0:成功;-1:失败。

头文件:dos.h函数3。

atof()将字符串转换成浮点数的函数原形:double atof(const char *s)功能:把s所指向的字符串转换成double类型。

s格式为:符号数字.数字E符号数字返回值:字符串的转换值。

头文件:math.h、stdlib.h函数4。

atoi()将字符串转换成整型数的函数原形:int atoi(const char *s)功能:把s所指向的字符串转换成int类型。

s格式为:符号数字返回值:字符串的转换值。

若出错则返回0。

头文件:stdlib.h函数5。

atol()将字符串转换成长整型数的函数原形:long atol(const char *s)功能:把s所指向的字符串转换成long int类型。

s格式为:符号数字返回值:字符串的转换值。

C语言函数大全-h开头-完整版

C语言函数大全-h开头-完整版

/* pragma warn -par reduces warnings which occur due to the non use */ /* of the parameters errval, bp and si to the handler. */ #pragma warn -par int handler(int errval,int ax,int bp,int si) { static char msg[80]; unsigned di; int drive; int errorno; di= _DI; /* if this is not a disk error then it was another device having trouble */ if (ax < 0) { /* report the error */ error_win("Device error"); /* and return to the program directly requesting abort */ hardretn(ABORT); } /* otherwise it was a disk error */ drive = ax & 0x00FF; errorno = di & 0x00FF; /* report which error it was */ sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ", err_msg[errorno], 'A' + drive); /* return to the program via dos interrupt 0x23 with abort, retry */ /* or ignore as input by the user. */ hardresume(error_win(msg)); return ABORT; } #pragma warn +par int main(void) { /* install our handler on the hardware problem interrupt */ harderr(handler); clrscr(); printf("Make sure there is no disk in drive A:\n"); printf("Press any key ....\n"); getch(); printf("Trying to access drive A:\n"); printf("fopen returned %p\n",fopen("A:temp.dat", "w")); return 0; }

C语言math.h中常用函数

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语言常用函数

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值,否则返回0int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回int 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.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 modf(double value,double *iptr) 将双精度数value分解成尾数和阶double fmod(double x,double y) 返回x/y的余数3、字符串处理本分类的函数用于对字符串进行合并、比较等操作头文件 string.hchar stpcpy(char *dest,const char *src) 将字符串src复制到destchar strcat(char *dest,const char *src) 将字符串src添加到dest末尾char strchr(const char *s,int c) 眷索并返回字符c在字符串s中第一次出现的位置int strcmp(const char *s1,const char *s2) 比较字符串s1与s2的大小,并返回s1-s2char strcpy(char *dest,const char *src) 将字符串src复制到destsize_t strcspn(const char *s1,const char *s2) 扫描s1,返回在s1中有,在s2中也有的字符个数char strdup(const char *s) 将字符串s复制到最近建立的单元int stricmp(const char *s1,const char *s2) 比较字符串s1和s2,并返回s1-s2size_t strlen(const char *s) 返回字符串s的长度char strlwr(char *s)将字符串s中的大写字母全部转换成小写字母,并返回转换后的字符串char strncat(char *dest,const char *src,size_t maxlen)将字符串src中最多maxlen个字符复制到字符串dest中int strncmp(const char *s1,const char *s2,size_t maxlen)比较字符串s1与s2中的前maxlen个字符char strncpy(char *dest,const char *src,size_t maxlen)复制src中的前maxlen个字符到dest中int strnicmp(const char *s1,const char *s2,size_t maxlen)比较字符串s1与s2中的前maxlen个字符char strnset(char *s,int ch,size_t n)将字符串s的前n个字符置于ch中char strpbrk(const char *s1,const char *s2)扫描字符串s1,并返回在s1和s2中均有的字符个数char strrchr(const char *s,int c)扫描最后出现一个给定字符c的一个字符串schar strrev(char *s)将字符串s中的字符全部颠倒顺序重新排列,并返回排列后的字符串char strset(char *s,int ch)将一个字符串s中的所有字符置于一个给定的字符chsize_t strspn(const char *s1,const char *s2)扫描字符串s1,并返回在s1和s2中均有的字符个数char strstr(const char *s1,const char *s2)扫描字符串s2,并返回第一次出现s1的位置char strtok(char *s1,const char *s2)检索字符串s1,该字符串s1是由字符串s2中定义的定界符所分隔char strupr(char *s)将字符串s中的小写字母全部转换成大写字母,并返回转换后的字符串4、输入输出函数该分类用于处理包括文件、控制台等各种输入输出设备,各种函数以“流”的方式实现头文件 stdio.hC语言输入输出函数有很多,标准I/O函数中包含了如下几个常用的函数:scanf,printf,getc,putc,getchar,putchar,gets,puts,fgets,fputs,fge tc,fputc,fscanf,fprintf等.int scanf(const char *format, arg_list)scanf主要从标准输入流中获取参数值,format为指定的参数格式及参数类型,如scanf("%s,%d",str,icount);它要求在标准输入流中输入类似"son of bitch,1000"这样的字符串,同时程序会将"son of bitch"给str,1000给icount.scanf函数的返回值为int值,即成功赋值的个数,在上例中如果函数调用成功,则会返回2,所以我们在写程序时,可以通过语句if(scanf("%s,%d",str,icount) != 2){...}来判断用户输入是否正确.int printf(const char *format, arg_list)printf主要是将格式化字符串输出到标准输出流中,在stdio.h头文件中定义了标准的输入和输出,分别是stdin,stdout.arg_list可以是变量名,也可以是表达式,但最终都会以值的形式填充进format中.int getc(FILE *fp)getc主要是从文件中读出一个字符.常用的判断文件是否读取结束的语句为:(ch = getc(fp)) != EOF.EOF为文件结束标志,定义在stdio.h中,就像EXIT_SUCCESS,EXIT_FAILURE定义在stdlib.h中一样,文件也可以被理解为一种流,所以当fp为stdin时,getc(stdin)就等同于getchar()了.int putc(int ch,FILE *fp)putc主要是把字符ch写到文件fp中去.如果fp为stdout,则putc就等同于putchar()了.int getchar(void)getchar主要是从标准输入流读取一个字符.默认的标准输入流即stdio.h 中定义的stdin.但是从输入流中读取字符时又涉及到缓冲的问题,所以并不是在屏幕中敲上一个字符程序就会运行,一般是通过在屏幕上敲上回车键,然后将回车前的字符串放在缓冲区中,getchar就是在缓冲区中一个一个的读字符.当然也可以在while循环中指定终止字符,如下面的语句:while ((c = getchar()) != '#')这是以#来结束的.int putchar(int ch)putchar(ch)主要是把字符ch写到标准流stdout中去.char * gets(char *str)gets主要是从标准输入流读取字符串并回显,读到换行符时退出,并会将换行符省去.int puts(char *str)puts主要是把字符串str写到标准流stdout中去,并会在输出到最后时添加一个换行符.char *fgets(char *str, int num, FILE *fp)str是存放读入的字符数组指针,num是最大允许的读入字符数,fp是文件指针.fgets的功能是读一行字符,该行的字符数不大于num-1.因为fgets函数会在末尾加上一个空字符以构成一个字符串.另外fgets在读取到换行符后不会将其省略.int fputs(char *str, file *fp)fputs将str写入fp.fputs与puts的不同之处是fputs在打印时并不添加换行符.int fgetc(FILE *fp)fgetc从fp的当前位置读取一个字符.int fputc(int ch, file *fp)fputc是将ch写入fp当前指定位置.int fscanf(FILE *fp, char *format,...)fscanf按照指定格式从文件中出读出数据,并赋值到参数列表中.int fprintf(FILE *fp, char *format,...)fprintf将格式化数据写入流式文件中.5、控制台输入输出函数该类函数主要包含了一些文本模式的屏幕控制函数,象绘画窗口、显示彩色文本,不是 Ansi标准函数,比如getch()函数等等。

c语言 除法函数

c语言 除法函数

C语言除法函数1. 函数的定义C语言中的除法函数是用来执行除法运算的函数,它用于将两个数相除并返回结果。

C语言中的除法函数是通过使用除法运算符/来实现的。

函数定义的一般形式如下:int divide(int dividend, int divisor);其中,divide是函数名,int表示函数返回值的类型,dividend和divisor是函数的参数。

2. 函数的用途除法函数的主要用途是执行除法运算,即将一个数除以另一个数并返回结果。

除法运算在数学和计算机科学中都是非常常见的运算,它可以用来解决各种实际问题,例如计算平均值、比率、百分比等。

除法函数在编程中也非常有用,它可以用来实现各种算法和逻辑,例如计算商、求解方程、计算余数等。

除法函数在编程中经常与其他数学函数和逻辑运算符一起使用,以实现复杂的计算和逻辑操作。

3. 函数的工作方式除法函数的工作方式非常简单,它将两个数相除并返回结果。

函数使用除法运算符/来执行除法运算,然后将结果返回给调用者。

除法函数的具体工作过程如下:1.接收两个整数参数dividend和divisor。

2.使用除法运算符/将dividend除以divisor,得到商。

3.将商作为函数的返回值返回给调用者。

以下是一个简单的除法函数的示例代码:int divide(int dividend, int divisor) {return dividend / divisor;}在调用这个除法函数时,可以将需要进行除法运算的两个数作为参数传递给函数,并接收函数返回的结果。

int result = divide(10, 2); // 将10除以2,得到结果54. 注意事项在使用除法函数时,需要注意以下几点:•除数不能为零:在进行除法运算时,除数不能为零,否则会导致运行时错误。

因为数学中除以零是没有意义的,所以除法函数在执行之前通常会检查除数是否为零,并在除数为零时返回一个错误或抛出一个异常。

c语言通用系统函数

c语言通用系统函数

c语言通用系统函数C语言通用系统函数C语言是一种广泛应用于系统编程和嵌入式开发的编程语言。

在C 语言中,系统函数起到了重要的作用,为程序员提供了操作系统底层功能的接口。

本文将介绍一些常用的C语言通用系统函数,帮助读者更好地理解和应用这些函数。

1. 输入输出函数C语言中的输入输出函数主要包括printf、scanf、getchar和putchar等。

其中,printf函数用于将格式化的数据输出到标准输出设备(通常是显示器),而scanf函数用于从标准输入设备(通常是键盘)读取格式化的数据。

getchar函数用于从标准输入设备读取一个字符,而putchar函数用于将一个字符输出到标准输出设备。

2. 字符串处理函数C语言中的字符串处理函数主要包括strlen、strcpy、strcat和strcmp等。

其中,strlen函数用于计算字符串的长度,strcpy函数用于将一个字符串复制到另一个字符串中,strcat函数用于将一个字符串连接到另一个字符串的末尾,而strcmp函数用于比较两个字符串是否相等。

3. 数学函数C语言中的数学函数主要包括fabs、sqrt、pow和rand等。

其中,fabs函数用于计算一个浮点数的绝对值,sqrt函数用于计算一个数的平方根,pow函数用于计算一个数的幂次方,而rand函数用于生成一个伪随机数。

4. 文件操作函数C语言中的文件操作函数主要包括fopen、fclose、fread和fwrite 等。

其中,fopen函数用于打开一个文件,fclose函数用于关闭一个文件,fread函数用于从文件中读取数据,而fwrite函数用于将数据写入到文件中。

5. 内存管理函数C语言中的内存管理函数主要包括malloc、free、calloc和realloc 等。

其中,malloc函数用于动态分配内存空间,free函数用于释放之前分配的内存空间,calloc函数用于动态分配并初始化内存空间,而realloc函数用于重新分配之前分配的内存空间。

C语言中KeilC51库函数大全

Keil C51库函‎数参考C51强大‎功能及其高‎效率的重要‎体现之一在‎于其丰富的‎可直接调用‎的库函数,多使用库函‎数使程序代‎码简单,结构清晰,易于调试和‎维护,下面介绍C‎51的库函‎数系统。

第一节本征库函数‎(intri‎nsic routi‎n e s)和非本征证‎库函数C51提供‎的本征函数‎是指编译时‎直接将固定‎的代码插入‎当前行,而不是用A‎C ALL和‎L CALL‎语句来实现‎,这样就大大‎提供了函数‎访问的效率‎,而非本征函‎数则必须由‎A CALL‎及LCAL‎L调用。

C51的本‎征库函数只‎有9个,数目虽少,但都非常有‎用,列如下:_crol‎_,_cror‎_:将char‎型变量循环‎向左(右)移动指定位‎数后返回_iror‎_,_irol‎_:将int型‎变量循环向‎左(右)移动指定位‎数后返回_lrol‎_,_lror‎_:将long‎型变量循环‎向左(右)移动指定位‎数后返回_nop_‎:相当于插入‎N OP_test‎b it_:相当于JB‎C bitva‎r测试该位‎变量并跳转‎同时清除。

_chkf‎l oat_‎:测试并返回‎源点数状态‎。

使用时,必须包含#inclu‎c le <intri‎n s.h>一行。

如不说明,下面谈到的‎库函数均指‎非本征库函‎数。

第二节几类重要库‎函数1. 专用寄存器‎i nclu‎d e文件例如803‎1、8051均‎为REG5‎1.h其中包括‎了所有80‎51的SF‎R及其位定‎义,一般系统都‎必须包括本‎文件。

2. 绝对地址i‎n clud‎e文件ab‎s acc.h该文件中实‎际只定义了‎几个宏,以确定各存‎储空间的绝‎对地址。

3. 动态内存分‎配函数,位于std‎l ib.h中4. 缓冲区处理‎函数位于“strin‎g.h”中其中包括拷‎贝比较移动‎等函数如:memcc‎p y memch‎r memcm‎p memcp‎y memmo‎v e memse‎t这样很方便‎地对缓冲区‎进行处理。

C语言函数大全(T开头)

函数大全(t开头) 61函数名:tan功能:正切函数用法:double tan(double x);程序例:#include<stdio.h>#include<math.h>int main(void){double result,x;x=0.5;result=tan(x);printf("The tan of%lf is%lf\n",x,result);return0;}函数名:tanh功能:双曲正切函数用法:double tanh(double x);程序例:#include<stdio.h>#include<math.h>int main(void){double result,x;x=0.5;result=tanh(x);printf("The hyperbolic tangent of%lf is%lf\n",x,result); return0;}函数名:tell功能:取文件指针的当前位置用法:long tell(int handle);程序例:#include<string.h>#include<stdio.h>#include<fcntl.h>#include<io.h>int main(void){int handle;char msg[]="Hello world";if((handle=open("TEST.$$$",O_CREAT|O_TEXT|O_APPEND))==-1) {perror("Error:");return1;}write(handle,msg,strlen(msg));printf("The file pointer is at byte%ld\n",tell(handle));close(handle);return0;}函数名:textattr功能:设置文本属性用法:void textattr(int attribute);程序例:#include<conio.h>int main(void){int i;clrscr();for(i=0;i<9;i++){textattr(i+((i+1)<<4));cprintf("This is a test\r\n");}return0;}函数名:textbackground功能:选择新的文本背景颜色用法:void textbackground(int color);程序例:#include<conio.h>int main(void){int i,j;clrscr();for(i=0;i<9;i++){for(j=0;j<80;j++)cprintf("C");cprintf("\r\n");textcolor(i+1);textbackground(i);}return0;}函数名:textcolor功能:在文本模式中选择新的字符颜色用法:void textcolor(int color);程序例:#include<conio.h>int main(void){int i;for(i=0;i<15;i++){textcolor(i);cprintf("Foreground Color\r\n");}return0;}函数名:textheight功能:返回以像素为单位的字符串高度用法:int far textheight(char far*textstring);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>int main(void){/*request auto detection*/int gdriver=DETECT,gmode,errorcode;int y=0;int i;char msg[80];/*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*/}/*draw some text on the screen*/for(i=1;i<11;i++){/*select the text style,direction,and size*/settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);/*create a message string*/sprintf(msg,"Size:%d",i);/*output the message*/outtextxy(1,y,msg);/*advance to the next text line*/y+=textheight(msg);}/*clean up*/getch();closegraph();return0;}函数名:textmode功能:将屏幕设置成文本模式用法:void textmode(int mode);程序例:#include<conio.h>int main(void){textmode(BW40);cprintf("ABC");getch();textmode(C40);cprintf("ABC");getch();textmode(BW80);cprintf("ABC");getch();textmode(C80);cprintf("ABC");getch();textmode(MONO);cprintf("ABC");getch();return0;}函数名:textwidth功能:返回以像素为单位的字符串宽度用法:int far textwidth(char far*textstring);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>int main(void){/*request auto detection*/int gdriver=DETECT,gmode,errorcode;int x=0,y=0;int i;char msg[80];/*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*/}y=getmaxy()/2;settextjustify(LEFT_TEXT,CENTER_TEXT); for(i=1;i<11;i++){/*select the text style,direction,and size*/settextstyle(TRIPLEX_FONT,HORIZ_DIR,i);/*create a message string*/sprintf(msg,"Size:%d",i);/*output the message*/outtextxy(x,y,msg);/*advance to the end of the text*/x+=textwidth(msg);}/*clean up*/getch();closegraph();return0;}函数名:time功能:取一天的时间用法:logn time(long*tloc);程序例:#include<time.h>#include<stdio.h>#include<dos.h>int main(void){time_t t;t=time(NULL);printf("The number of seconds since January1,1970is%ld",t); return0;}函数名:tmpfile功能:以二进制方式打开暂存文件用法:FILE*tmpfile(void);程序例:#include<stdio.h>#include<process.h>int main(void){FILE*tempfp;tempfp=tmpfile();if(tempfp)printf("Temporary file created\n");else{printf("Unable to create temporary file\n");exit(1);}return0;}函数名:tmpnam功能:创建一个唯一的文件名用法:char*tmpnam(char*sptr);程序例:#include<stdio.h>int main(void){char name[13];tmpnam(name);printf("Temporary name:%s\n",name); return0;}函数名:tolower功能:把字符转换成小写字母用法:int tolower(int c);程序例:#include<string.h>#include<stdio.h>#include<ctype.h>int main(void){int length,i;char*string="THIS IS A STRING"; length=strlen(string);for(i=0;i<length;i++){string[i]=tolower(string[i]);}printf("%s\n",string);return0;}函数名:toupper功能:把字符转换成大写字母用法:int toupper(int c);程序例:#include<string.h>#include<stdio.h>#include<ctype.h>int main(void){int length,i;char*string="this is a string";length=strlen(string);for(i=0;i<length;i++){string[i]=toupper(string[i]);}printf("%s\n",string);return0;}函数名:tzset功能:UNIX时间兼容函数用法:void tzset(void);程序例:#include<time.h>#include<stdlib.h>#include<stdio.h>int main(void){time_t td;putenv("TZ=PST8PDT");tzset();time(&td);printf("Current time=%s\n",asctime(localtime(&td))); return0;}。

c语言标准输入输出函数

c语言标准输入输出函数C语言是一种广泛应用的编程语言,它提供了许多标准库函数来实现输入和输出操作。

在C语言中,标准输入输出函数是非常重要的,用于与用户交互和进行数据的读取和输出。

本文将详细介绍C语言中的标准输入输出函数,并对其进行逐一讲解。

在C语言中,标准输入输出函数主要包括以下几个:1. printf函数:用于向屏幕上输出内容。

它的基本用法是:printf("格式字符串",变量列表);其中,格式字符串是一个由普通字符和转义序列组成的字符串,用来描述输出的格式和内容;变量列表包含了要输出的变量的值。

例如,下面的代码将在屏幕上输出"Hello World!":```c#include <stdio.h>int main() {printf("Hello World!");return 0;}```2. scanf函数:用于从键盘上读取输入。

它的基本用法是:scanf("格式字符串",变量列表);其中,格式字符串和变量列表的含义与printf函数类似,用来描述输入的格式和存储变量的位置。

例如,下面的代码将从键盘上读取一个整数,并输出它的值:```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);printf("您输入的整数是:%d", num);return 0;}```3. gets函数:用于从键盘上读取一行字符串。

它的基本用法是:gets(字符串变量);其中,字符串变量用来存储读取到的字符串。

例如,下面的代码将从键盘上读取一行字符串,并输出它的内容:```c#include <stdio.h>int main() {char str[100];printf("请输入一行字符串:");gets(str);printf("您输入的字符串是:%s", str);return 0;}```需要注意的是,gets函数是不安全的,容易导致缓冲区溢出,因此在实际应用中应尽量避免使用。

C语言常用函数名及用法

字符函数和字符串函数头文件:字符串函数头文件:#include<>字符函数头文件:#include<ctype>putchar:输出一个putchar(a):输出字符变量a的值,(其中a可为字符变量,整形变量,字符常量,整形常量)getchar:输入一个字符a=getchar(); putchar(a);结果为bprintf(格式控制符,输出列表);scanf(格式控制符,地址列表);输入形式与格式控制部分对应1.当为两个连续输入时:scanf(“%d%d”,&a,&b);输入量数据之间可为:一个或多个空格,也可以用enter,tab无逗号时输入时不能用逗号作分隔。

2.格式控制中两%d有两个空格,输入时两数据间应有两个空格或两个以上。

3.当为“:”时输入时应对应一样,当为:scanf(“a=%d,b=%d”,&a,&b);输入a=12,b=22。

4.当格式控制符为%c时,输入时空格与转义字符都作为有效字符记录在里面:scanf(“%c%c%c”,&a,&b,&c); 输入时:abc↙空间不能插空格或其他符5. Scanf(“%d%c%f”,&a,&b,&c); 输入时1234a123h26↙在输入遇到时空格回车 tab或其他非法输入就会认定输入完毕Gets (字符数组):读入字符串函数Gets(str)从键盘键入ab↙括号里为字符数组str的起始地址,Puts(字符数组):输出字符串函数Strcat(字符数组1,字符数组2):字符串连接函数(2连接在1后面)Strcpy和strncpy:字符串复制函数Strcpy(字符数组1,字符数组2):将2复制到1数组1 要为数组名,字符串2可以为数组名或者字符串Strncpy(str1,str2,2):将str2的前两个字符复制到str1,取代str1的前两个字符Strcmp:字符串比较函数Strcmp(str1,str2):相等则为0(对字符串自左向右逐个字母进行比较)Strlen(字符数组):测字符串的实际长度Strlwr(字符串)将字符串转换为大写Strupr(字符串)将字符串转换为小写数学函数#include <>或#include”math”pow(a,b):计算a的b次方sqrt(a):计算根号alog(x):计算以e为底x的对数log10(x):计算以10为底x的对数abs(x):求整数x的绝对值。

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

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。

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)函数名:功用:串行I/O通讯用法:int (int cmd。

char abyte。

int port)函数名:sdisk功用:软硬盘I/O用法:int sdisk(int cmd。

int drive。

int head。

int track。

int sectorint nsects。

void *buffer)函数名:sequip功能:检查设备用法:int sequip(void)函数名:skey功能:直接使用BIOS服务的键盘接口用法:XXX(int cmd)函数名:smemory功用:返回储备块大小用法:XXX(void)函数名:sprint功用:间接利用BIOS效劳的打印机I/O用法:int sprint(int cmd。

int byte。

int port)函数名:stime功能:读取或设置BIOS时间用法:long stime(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功能:分配主存储器用法:XXX(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功能:清除图形视区用法:XXX(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);函数名:_XXX功用:树立一个新文件或重写一个已存在的文件用法: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);函数名:ctrlbrk功用:设置Ctrl-Break处置惩罚步伐用法:void ctrlbrk(*fptr)(void);函数名:XXX功能:将程序的执行暂停一段时间(毫秒)用法: void delay(unsigned milliseconds);函数名:delline功能:在文本窗口中删去一行用法:XXX(void);函数名:detectgraph功能:通过检测硬件确定图形驱动程序和模式用法: XXX(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功用:画多边形用法: XXX(int numpoints。

int far *polypoints);函数名:dup 功用:复制一个文件句柄用法:int dup(int handle);函数名:dup2功能:复制文件句柄用法: int dup2(int oldhandle。

int newhandle);函数名:ecvt功能:把一个浮点数转换为字符串用法: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。

相关文档
最新文档