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

C语言函数大全C语言作为一种广泛应用的计算机编程语言,其函数是程序设计中不可或缺的部分。
C语言函数大全涵盖了C语言中常用的各种函数,包括数学函数、字符串函数、输入输出函数等,本文将对这些函数进行详细介绍。
一、数学函数。
1. abs函数。
abs函数用于返回一个整数的绝对值,其原型为int abs(int x)。
2. pow函数。
pow函数用于计算一个数的幂,其原型为double pow(double x, double y)。
3. sqrt函数。
sqrt函数用于计算一个数的平方根,其原型为double sqrt(double x)。
4. sin函数。
sin函数用于计算一个角度的正弦值,其原型为double sin(double x)。
5. cos函数。
cos函数用于计算一个角度的余弦值,其原型为double cos(double x)。
6. tan函数。
tan函数用于计算一个角度的正切值,其原型为double tan(double x)。
二、字符串函数。
1. strlen函数。
strlen函数用于返回一个字符串的长度,其原型为size_t strlen(const char s)。
2. strcpy函数。
strcpy函数用于将一个字符串复制到另一个字符串中,其原型为charstrcpy(char dest, const char src)。
3. strcat函数。
strcat函数用于将一个字符串追加到另一个字符串的末尾,其原型为char strcat(char dest, const char src)。
4. strcmp函数。
strcmp函数用于比较两个字符串,其原型为int strcmp(const char s1, const char s2)。
5. strchr函数。
strchr函数用于在一个字符串中查找指定字符的位置,其原型为charstrchr(const char s, int c)。
c#函数大全

1到9的平方和static void Main(string[] args){int h=0;for(int i=1;i<=9;i++){h=h+i*i;}Console.WriteLine (h);}1到100的累加static void Main(string[] args){ int sum = 0;for (int i = 1;i<=100;i++)sum = sum +i;Console.WriteLine("1到的累加总合为:{0}",sum);}}}10个行输出被7整除的数static void Main(string[] args){for(int i=100;i<=200;i++)for(int j=1;j<=10;j++) {if(i%7==0){ Console.Write ("{0}",i);break;}}7行倒三角for(int a=1;a<=7;a++){for(int b=1;b<=a;b++)Console.Write (" ");for(int c=1;c<=15-2*a;c++) {Console.Write ("*");}Console.Write ("\n");}乘法口诀表static void Main(string[] args){ int i,j; Console.WriteLine ("成法口决表");for(i=1;i<=9;i++){ for(j=1;j<=i;j++){ Console.Write("{0}*{1}={2};",j,i,(i*j));}Console.WriteLine ();}}}10的阶乘static void Main(string[] args){ int i=1; int n=1;do{ n=n*i;i++;}while (i<=10);Console.WriteLine ("10的阶乘结果为;{0}",n);}}For 循环求i的值static void Main(string[] args){ double s=0,x=1; //初始化for (int n=1;Math.Abs (x)>1e-8;n++,x*=(-1.0)*(2*n-3)/(2*n-1))s=s+x; s=s*4;Console.WriteLine ("pi的值是:{0}",s);}While循环求pi的值static void Main(string[] args){ double result =0,initial=1;//初始值 long deno = 1;int flag =1; while (Math.Abs (initial)>1e-8) //循环条件{ result =result+initial; //循环体,计算(Math.PI/4)deno=deno+2;flag=flag*(-1);initial=flag/Convert.ToDouble (deno);} result=result*4; //Math.PI值Console.WriteLine ("pi值是:{0}",result); //输出Math.PI值}}While 循环输出10的阶乘static void Main(string[] args){ int i=1; int n=1; while(i<=10){ n=n*i;i++;}Console.WriteLine ("10的阶乘结果为:{0}",n);}}百钱买百鸡static void Main(string[] args) {for(int g=0;g<20;g++) for(int m=0;m<35;m++) for(intx=0;x<100;x++){ if((g+m+x==100)&&(5*g+3*m+1/(3*x)==100))Console.WriteLine("值为;{0}\n 值为:{1}\n 值:{2}",g,m,x); }} }水仙花static void Main(string[] args) {int x=Convert.ToInt32 (Console.ReadLine ());int y=Convert.ToInt32 (Console.ReadLine ());int z=Convert.ToInt32 (Console.ReadLine ());if(x*100+y*10+z==x*x*x+y*y*y+z*z*z) Console.WriteLine ("水仙花");else Console.WriteLine ("不是水仙花");}}找6ji42能被两个数整除static void Main(string[] args){for(int j=0;j<=9;j++){ for(int i=0;i<=9;i++) {intx=60000+j*1000+i*100+42;if(x%32==0&&x%42==0) Console.WriteLine(x);}} }}正三角形的星using System;class Music{ static void Main(string[] args) { int i,j,b;捉司机using System;namespace ConsoleApplication1{class Class1 {static void Main(string[] args){int x=0;int y=0;for(x=0;x<=9;x++)for(y=0;y<=9;y++){double m=1000*x+100*x+10*y+y;for(int i=10;i<=100;i++)if(m==i*i)Console.WriteLine (m);}}}输出100到200中所有的素数static void Main(string[] args){ for(int i=100;i<=200;i++){ for(int j=2;j<=i;j++){if(i%j==0) break;if(j==i-1)Console.Write(i+"\t"); }}}}求2到10000间的完数static void Main(string[] args){ for (int j=2;j<=10000;j++){ int s=0;for(int i=1;i<j;i++){ if(j%i==0)s=s+i;}if(s==j) Console.WriteLine (j);} }}求两个数的最大公约数static void Main(string[] args){while(true){int a=Convert.ToInt32 (Console.ReadLine ());int b=Convert.ToInt32 (Console.ReadLine ()); if(a>b){ for(int c=a;c>0;c--){if(a%c==0&&b%c==0){ Console.WriteLine (c); break;}}}}}}判断输入的数是否为素数static void Main(string[] args){ while(true){int i; int x=Convert.ToInt32 (Console.ReadLine ()); for( i=2;i<x;i++){ if(x%i==0)Console.WriteLine ("x不是素数");break;}if( i==(x-1)) Console.WriteLine ("x是素数");}}}二原方程根的情况static void Main(string[] args){ double x1,x2; int a=Convert.ToInt32(Console.ReadLine()); int b=Convert.ToInt32(Console.ReadLine());int c=Convert.ToInt32(Console.ReadLine());doubled=b*b-4*a*c;if(a==0) Console.WriteLine("不是二元方程");if(d>0){ x1=(-b+System.Math.Sqrt(d))/(2*a);x2=(-b-System.Math.Sqrt(d))/(2*a);Console.WriteLine("第一个根:{0}\t第二个根:{1}\t",x1,x2);}if(d==0){ x1=-b/(2*a); x2=-b/(2*a); Console.WriteLine("第一个根:{0}\t第二个根:{1}\t",x1,x2);}} 歌德巴赫猜想static void Main(string[] args){ int m=Convert.ToInt32 (Console.ReadLine ());for(int x=6;x<m;x+=2){ for(int y=3;y<x/2;y++) if(prime(y)){int z=x-y;if(prime(z))Console.WriteLine ("结果为:x={0},y={1},z={2}",x,y,z); }}}static bool prime (int n){int i; for(i=2;i<=System.Math.Sqrt (n);i++) if(n%i==0)return false;return true;}}递归函数算任意数的阶乘static void Main(string[] args) { Console.WriteLine ("输入任意的数");int n=Convert.ToInt32 (Console.ReadLine ());double s=f(n);Console.WriteLine (f(n)); }static double f(int n){ double d=0;if(n==0||n==1) d=1; else d=f(n-1)*n;return d;}}函数比较三个数的大小static void Main(string[] args){int result=MaxThree(2,7,4); Console.WriteLine (result); }static int MaxTwo(int x,int y){ if(x>y) return x;else return y; }static int MaxThree(int x,int y,int z){ int temp;temp=MaxTwo(x,y);if(z>temp)return z;else return temp;}}}调用编成世界using System;namespace ConsoleApplication11{class Class1{static void Main(string[] args){string name =Convert.ToString(Console.ReadLine()); welcome( name); }static void welcome(string name){ for(int i=1;i<=5;i++)Console.WriteLine("欢迎你,{0}同志,这里是C#编程世界",name);}}大小写字母转换char c=Convert.ToChar(Console.ReadLine());if(c>='a'&&c<='z'){int b=(int)c-32;char ch=(char)b;Console.WriteLine(ch);}if(c>='A'&&c<='Z'){int d=(int)c+32;char ch=(char)d;Console.WriteLine(ch);}判断瑞年int year=Convert.ToInt32(Console.ReadLine());if(year%4==0&&year%100==0)//[if(year%400==0) ]Console.WriteLine("瑞年");elseConsole.WriteLine("不是瑞年");求最小公倍数int a=Convert.ToInt32 (Console.ReadLine());int b=Convert.ToInt32 (Console.ReadLine ());int d=Convert.ToInt32 (Console.ReadLine ());if(a>b&&a>d){for(int c=a;c>0;c--){if(c%a==0&&c%b==0&&c%d==0){Console.WriteLine (c);break;}正三角形的星using System;class Music{ static void Main(string[] args){ int i,j,b; for( i=1;i<=4;i++){ for(j=0;j<=4-i;j++) Console.Write(" ");for(b=1;b<=2*i-1;b++) Console.Write("*"); Console.Write("\n"); }}namespace ConsoleApplication1{ class Program { static void Main(string[] args){实验五第一题输入月号,输出月份的英文名称do {Console.WriteLine("请输入您需要的月份:");Console.WriteLine ("下面的程序将对它进行英文翻译."); int a=Convert.ToInt16 (Console.ReadLine ());switch(a){case(1): Console.WriteLine ("Jan");break; case(2):Console.WriteLine ("Feb");break;case(3): Console.WriteLine ("Mar");break;case(4): Console.WriteLine ("Apr");break;case(5):Console.WriteLine("May");break;case(6):Console.WriteLine ("Jun");break;case(7): Console.WriteLine ("Jul");break;case(8):Console.WriteLine ("Aug");break;case(9): Console.WriteLine ("Sep");break;case(10): Console.WriteLine ("Oct");break;case(11):Console.WriteLine ("Nov");break;case(12):Console.WriteLine ("Der");break;}}while(true); Console.ReadLine ();实验五第二题托儿所问题Console.WriteLine("请输入你的年龄大小:");int a =Convert.ToInt16(Console .ReadLine ());switch (a){ case (2): Console.WriteLine("please enter lower class"); break;case(3):Console.WriteLine("please enter lower class"); break;case(4): Console .WriteLine ("please enter middle class"); break;case(5): Console.WriteLine("please enter higher class"); break;case(6): Console .WriteLine ("please enter higher class"); break;}Console .ReadLine ();实验五第三题开发一个数学工具do{Console.WriteLine("欢迎使用本数学工具,本数学工具具有以下功能");Console.WriteLine("图形面积计算按1");Console.WriteLine("算术计算按2");Console.WriteLine("三角函数计算按3");Console.WriteLine("请输入数字选择您此次计算的类型");int x = int.Parse(Console.ReadLine());double area, v;switch (x){case (1):{Console.WriteLine("请输入字母选择您此次计算的图形面积的类型");Console.WriteLine("三角形的面积按1:"); Console.WriteLine("长方形的面积按2:");Console.WriteLine("圆形的面积按3:"); Console.WriteLine("梯形的面积按4:");int y = int.Parse(Console.ReadLine());switch (y){ case (1):{Console.WriteLine("请输入三角形的边q:");Console.WriteLine("请输入三角形的边p:");Console.WriteLine("请输入三角形的边l:");double q = Convert.ToInt64(Console.ReadLine());double p = double.Parse(Console.ReadLine());double l = double.Parse(Console.ReadLine());double h;if ((q + p) > l && (q + l) > p && (l + p) > q){ h = (1 / 2) * (q + p + l);rea = Math.Sqrt(h * (h - q) * (h - p) * (h - l));Console.WriteLine("面积="+area); }else{ Console.WriteLine("输入三边错误不能够成三角形");}break; }case (2):{Console.WriteLine("请输入长方形的短边q:"); Console.WriteLine("请输入长方形的长边p:");double q = Convert.ToInt64(Console.ReadLine()); double p = double.Parse(Console.ReadLine());area = q * p;Console.WriteLine("面积:"+area); break;}case (3):{Console.WriteLine("请输入园的半径q:");double q = Convert.ToInt64(Console.ReadLine()); area = q * q * Math.PI;Console.WriteLine("面积:"+area);break;}case (4):{Console.WriteLine("请输入上底的长度q:");Console.WriteLine("请输入下底的长度p:");Console.WriteLine("请输入高的长度h:");double q = Convert.ToInt64(Console.ReadLine());double p = double.Parse(Console.ReadLine());double h = double.Parse(Console.ReadLine());area = ((q + p) * h) / 2;Console.WriteLine("面积:"+area);break;}}break;}case (2):{Console.WriteLine("要算加法请输入1:");Console.WriteLine("要算减法请输入2:");Console.WriteLine("要算乘法请输入3:");Console.WriteLine("要算除法请输入4:");int k = Convert.ToInt16(Console.ReadLine());switch (k){ case (1):{ Console.WriteLine("请输入q:"); Console.WriteLine("请输入p:");double q = Convert.ToInt64(Console.ReadLine());double p = double.Parse(Console.ReadLine());v = q + p;Console.WriteLine("两数和:"+v); break; }case (2):{Console.WriteLine("请输入较大数q:");Console.WriteLine("请输入较小数p:");double q = Convert.ToInt64(Console.ReadLine());double p = double.Parse(Console.ReadLine());v = q - p;Console.WriteLine("两数差:"+v); break;}case (3):{Console.WriteLine("请输入被除数q:");Console.WriteLine("请输入除数p:");double q = Convert.ToInt64(Console.ReadLine());double p = double.Parse(Console.ReadLine());v = q / p;Console.WriteLine("两数商:" + v);break;}case (4):{Console.WriteLine("请输入其中要乘的数一q:");Console.WriteLine("请输入另一个乘数二p:"); double q = Convert.ToDouble(Console.ReadLine());double p = double.Parse(Console.ReadLine());v = q * p;Console.WriteLine("两数积:"+v); break;} }break;}case (3):{ Console.WriteLine("要想求sin请输入1:");Console.WriteLine("要想求cos请输入2:");Console.WriteLine("要想求tan请输入3:"); int m = Convert.ToInt16(Console.ReadLine());switch (m){case (1):{Console.WriteLine("请输入您的度数:");double q= double .Parse (Console .ReadLine ());q=Math.Sin ();Console.WriteLine(m);break;}case (2):{Console.WriteLine("请输入您的度数:");double q = Convert .ToInt64 (Console.ReadLine());q = Math.Cos();Console.WriteLine(q); break; }case (3):{Console.WriteLine("请输入您的度数:");double q = Convert .ToDouble (Console.ReadLine()); q = Math.Tan();Console.WriteLine(q);break; }}break;} while(true); Console.ReadLine();}}}试验七第一题求e的值double i, n=1;double sum=0;for (i = 1; i <= 10; i++){ n = n*i;sum = sum + 1/n ; Console.WriteLine(sum); }Console.ReadLine();实验七第二题方法一m和n的最大公约数int i,temp=0;Console.WriteLine("请输入您的数a:");int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入您的数b");int b = Convert.ToInt32(Console.ReadLine());for (i = 1; i <=a && i<= b; i++){ if ((a % i == 0) && (b % i == 0)) temp = i;} Console .WriteLine (temp); //Console.ReadLine();/ 实验七第三题人口增长率Console.WriteLine("该程序有三种%数,分别是%5,%2,%1。
C语言常用数学函数

常用数学函数abs(计算整型数的绝对值)相关函数labs, fabs表头文件#include<stdlib.h>定义函数int abs (int j)函数说明abs()用来计算参数j的绝对值,然后将结果返回。
返回值返回参数j的绝对值结果。
范例#ingclude <stdlib.h>main(){int ansert;answer = abs(-12);printf("|-12| = %d\n", answer);}执行|-12| = 12acos(取反余弦函数数值)相关函数asin , atan , atan2 , cos , sin , tan表头文件#include <math.h>定义函数double acos (double x);函数说明acos()用来计算参数x的反余弦值,然后将结果返回。
参数x范围为-1至1之间,超过此范围则会失败。
返回值返回0至PI之间的计算结果,单位为弧度,在函数库中角度均以弧度来表示。
错误代码EDOM参数x超出范围。
附加说明使用GCC编译时请加入-lm。
范例#include <math.h>main (){double angle;angle = acos(0.5);printf("angle = %f\n", angle);}执行angle = 1.047198asin(取反正弦函数值)相关函数acos , atan , atan2 , cos , sin , tan表头文件#include <math.h>定义函数double asin (double x)函数说明asin()用来计算参数x的反正弦值,然后将结果返回。
参数x范围为-1至1之间,超过此范围则会失败。
返回值返回-PI/2之PI/2之间的计算结果。
错误代码EDOM参数x超出范围附加说明使用GCC编译时请加入-lm范例#include<math.h>main(){double angle;angle = asin (0.5);printf("angle = %f\n",angle);}执行angle = 0.523599atan(取反正切函数值)相关函数acos,asin,atan2,cos,sin,tan表头文件#include<math.h>定义函数double atan(double x);函数说明atan()用来计算参数x的反正切值,然后将结果返回。
c语言常用函数大全及详解

C语言常用函数包括:1.printf函数:用于在控制台输出数据。
2.scanf函数:用于从控制台读取用户输入的数据。
3.strlen函数:用于计算字符串的长度。
4.strcmp函数:用于比较两个字符串的大小。
5.strcpy函数:用于将一个字符串复制到另一个字符串中。
6.strcat函数:用于将一个字符串连接到另一个字符串的末尾。
7.strchr函数:用于查找字符串中指定字符的位置。
8.strstr函数:用于查找字符串中指定子串的位置。
9.atoi函数:用于将字符串转换为整数。
10.atof函数:用于将字符串转换为浮点数。
11.malloc函数:用于动态分配内存空间。
12.free函数:用于释放动态分配的内存空间。
13.memcpy函数:用于将一段内存区域的数据复制到另一段内存区域。
14.memset函数:用于将一段内存区域的数据设置为指定的值。
15.abs函数:用于计算整数的绝对值。
16.rand函数:用于生成随机数。
17.srand函数:用于设置随机数生成器的种子。
18.time函数:用于获取当前的系统时间。
19.localtime函数:用于将时间戳转换为本地时间。
20.strtol函数:用于将字符串转换为长整型数。
21.strtod函数:用于将字符串转换为双精度浮点数。
22.fprintf函数:用于将数据格式化输出到文件中。
23.fscanf函数:用于从文件中读取格式化的数据。
24.fgets函数:用于从文件中读取一行数据。
25.fputs函数:用于将数据写入文件中。
26.fopen函数:用于打开文件。
27.fclose函数:用于关闭文件。
28.feof函数:用于判断文件是否已经到达文件末尾。
29.ferror函数:用于判断文件操作是否发生错误。
30.fprintf函数:用于将数据格式化输出到文件中。
c语言常用函数大全及详解

c语言常用函数大全及详解C语言是一种通用的、面向过程的编程语言,被广泛应用于系统软件、嵌入式开发以及科学计算领域。
在C语言中,函数是一种模块化编程的基本方法,通过函数可以将一段代码进行封装和复用,提高了代码的可读性和可维护性。
本文将介绍一些C语言中常用的函数,并详细解释其用法及重要参数。
一、数学函数1. abs()函数函数原型:int abs(int x);函数功能:返回x的绝对值。
参数说明:x为一个整数。
2. pow()函数函数原型:double pow(double x, double y);函数功能:计算x的y次方。
参数说明:x和y为两个double类型的实数。
3. sqrt()函数函数原型:double sqrt(double x);函数功能:计算x的平方根。
参数说明:x为一个double类型的实数。
二、字符串函数1. strcpy()函数函数原型:char* strcpy(char* destination, const char* source);函数功能:将source字符串复制到destination字符串。
参数说明:destination为目标字符串,source为源字符串。
2. strlen()函数函数原型:size_t strlen(const char* str);函数功能:计算str字符串的长度。
参数说明:str为一个以'\0'结尾的字符串。
3. strcat()函数函数原型:char* strcat(char* destination, const char* source);函数功能:将source字符串拼接到destination字符串的末尾。
参数说明:destination为目标字符串,source为源字符串。
三、文件操作函数1. fopen()函数函数原型:FILE* fopen(const char* filename, const char* mode);函数功能:打开一个文件,并返回文件指针。
C语言中的数学函数

C语言中的数学函数数学函数在计算机编程中起着重要的作用,尤其是在C语言中。
C语言提供了丰富的数学函数库,方便开发者进行各种数学计算和操作。
本文将介绍C语言中常用的数学函数,包括数值运算、三角函数、指数函数等。
一、数值运算函数1.1 绝对值函数(fabs)绝对值函数fabs(x)返回x的绝对值。
例如,fabs(-5)的返回值是5。
1.2 向上取整函数(ceil)向上取整函数ceil(x)返回大于或等于x的最小整数。
例如,ceil(4.2)的返回值是5。
1.3 向下取整函数(floor)向下取整函数floor(x)返回小于或等于x的最大整数。
例如,floor(4.8)的返回值是4。
1.4 平方根函数(sqrt)平方根函数sqrt(x)返回x的平方根。
例如,sqrt(16)的返回值是4。
1.5 幂运算函数(pow)幂运算函数pow(x, y)返回x的y次方。
例如,pow(2, 3)的返回值是8。
二、三角函数2.1 正弦函数(sin)正弦函数sin(x)返回以弧度为单位的角x的正弦值。
例如,sin(0)的返回值是0。
2.2 余弦函数(cos)余弦函数cos(x)返回以弧度为单位的角x的余弦值。
例如,cos(3.14)的返回值是-1。
2.3 正切函数(tan)正切函数tan(x)返回以弧度为单位的角x的正切值。
例如,tan(0.8)的返回值是0.999.2.4 反正弦函数(asin)反正弦函数asin(x)返回x的反正弦值,以弧度为单位。
例如,asin(1)的返回值是1.57.2.5 反余弦函数(acos)反余弦函数acos(x)返回x的反余弦值,以弧度为单位。
例如,acos(0)的返回值是1.57.三、指数函数3.1 自然指数函数(exp)自然指数函数exp(x)返回e的x次方。
其中e的值约为2.71828。
例如,exp(1)的返回值是2.71828.3.2 对数函数(log)对数函数log(x)返回以e为底,x的对数值。
附录D C语言常用库函数

帮助文件目录语法:❖if(表达式) 语句❖if(表达式)语句1 else 语句2❖if (表达式1)语句1else if(表达式2)语句2else if(表达式3)语句3else if(表达式m)语句melse 语句n❖switch(表达式){ case 常量表达式1:语句1case 常量表达式2:语句2┋case 常量表达式n:语句ndefault :语句n+1}❖while (表达式) 语句;❖do 语句 while(表达式);❖for(表达式1;表达式2;表达式3)语句❖break;❖continue;附录C ASCII编码对照表附录E 常用头文件#include <assert.h> //设定插入点#include <ctype.h> //字符处理#include <errno.h> //定义错误码#include <float.h> //浮点数处理#include <fstream.h> //文件输入/输出#include <iomanip.h> //参数化输入/输出#include <iostream.h> //数据流输入/输出#include <limits.h> //定义各种数据类型最值常量#include <locale.h> //定义本地化函数#include <math.h> //定义数学函数#include <stdio.h> //定义输入/输出函数#include <stdlib.h> //定义杂项函数及内存分配函数#include <string.h> //字符串处理#include <strstrea.h> //基于数组的输入/输出#include <time.h> //定义关于时间的函数#include <wchar.h> //宽字符处理及输入/输出#include <wctype.h> //宽字符分类#include <complex> //复数类#include <ios> //基本输入/输出支持#include <iosfwd> //输入/输出系统使用的前置声明#include <iostream>#include <istream> //基本输入流#include <ostream> //基本输出流#include <queue> //STL 队列容器#include <set> //STL 集合容器#include <sstream> //基于字符串的流#include <stack> //STL 堆栈容器#include <stdexcept> //标准异常类#include <streambuf> //底层输入/输出支持#include <string> //字符串类#include <utility> //STL 通用模板类#include <vector> //STL 动态数组容器#include <dos.h>通用dos中断接口函数#include <conio.h>)驻留并退出函数附录D C语言常用库函数附录B C语言运算符优先级和结合性。
(完整版)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语言数学函数大全及详解

c语言数学函数大全及详解C语言提供了一系列的数学函数,这些函数包含在`math.h` 头文件中。
以下是一些常见的C 语言数学函数及其简要说明:1. fabs:-函数原型:`double fabs(double x);`-描述:返回`x` 的绝对值。
2. sqrt:-函数原型:`double sqrt(double x);`-描述:返回`x` 的平方根。
3. pow:-函数原型:`double pow(double x, double y);`-描述:返回`x` 的`y` 次方。
4. exp:-函数原型:`double exp(double x);`-描述:返回自然对数的底`e` 的`x` 次方。
5. log:-函数原型:`double log(double x);`-描述:返回`x` 的自然对数。
6. sin, cos, tan:-函数原型:- `double sin(double x);`- `double cos(double x);`- `double tan(double x);`-描述:分别返回`x` 的正弦、余弦和正切值。
这些函数中`x` 的单位是弧度。
7. asin, acos, atan:-函数原型:- `double asin(double x);`- `double acos(double x);`- `double atan(double x);`-描述:分别返回`x` 的反正弦、反余弦和反正切值。
返回的值是弧度。
8. sinh, cosh, tanh:-函数原型:- `double sinh(double x);`- `double cosh(double x);`- `double tanh(double x);`-描述:分别返回`x` 的双曲正弦、双曲余弦和双曲正切值。
9. ceil:-函数原型:`double ceil(double x);`-描述:返回不小于`x` 的最小整数值。
C语言中常用函数大全

(三)文件函数
mode: r:打开已存在文件,准备从文件中读取数据 ,不能写入 r+ :可读可写
w:创建一个新文件,准备写入;如文件已存在,此文件将被 空文件覆盖 w+:增加“读取”操作
2;字符ar(int c) 正常返回字 符代码值,出错返回 E OF (2)int putc(int c,FILE*strea m) 正常返回字 符代码值,出错返回 E OF strea m==stdou t(1)=(2) (3)int puts(char*strea m) 自动回车换 行
a:打开已存在文件,准备在文件尾部追加数 据,不能读取。 如文件不存在,侧创建此文 件,准备写入。
a+:增加“读取”
t:打开一个文 本文件(缺省值) b:打开一个二 进制文件
一:文件的打开 与关闭 1:打开文件 FILE * fopen (char*filen ame, char*mode) Filename:是字符串,表示打开的文件名,文件名前可 以带路径。 Mode:也是字符串,表示打开文 件的方式。 功能----按指定方式 打开文件。 返回值----如果文件打开成功,返回“文件结构体 指针”,否者返回 N ULL(如:文件不存在 或则 写文件时不能创建 )。 Fopen(“A:\\user\\asd.txt”,”r+”); 2:关闭文件 Int*fclos e(FILE*filen ame) 正常关闭返 回0;否者返回 非 0。
With:指定输入数 据的宽度,遇空格、Tab、\n 结束
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语言函数大全C语言函数大全

AAA.函数名: abort功能: 异常终止一个进程用法: void abort(void);程序例:#include <stdio.h>#include <stdlib.h>int main(void){printf("Calling abort()\n");abort();return 0; /* This is never reached */}函数名: abs功能: 求整数的绝对值用法: int abs(int i);程序例:#include <stdio.h>#include <math.h>int main(void){int number = -1234;printf("number: %d absolute value: %d\n", number, abs(number)); return 0;}函数名: absread, abswirte功能: 绝对磁盘扇区读、写数据用法: int absread(int drive, int nsects, int sectno, void *buffer); int abswrite(int drive, int nsects, in tsectno, void *buffer);程序例:/* absread example */#include <stdio.h>#include <conio.h>#include <process.h>#include <dos.h>int main(void){int i, strt, ch_out, sector;char buf[512];printf("Insert a diskette into drive A and press any key\n"); getch();sector = 0;if (absread(0, 1, sector, &buf) != 0){perror("Disk problem");exit(1);}printf("Read OK\n");strt = 3;for (i=0; i<80; i++){ch_out = buf[strt+i];putchar(ch_out);}printf("\n");return(0);}函数名: access功能: 确定文件的访问权限用法: int access(const char *, int amode);程序例:#include <stdio.h>#include <io.h>int (char *);int main(void){printf("Does NOTEXIST.FIL exist: %s\n",("NOTEXISTS.FIL") ? "YES" : "NO");return 0;}int (char *){return (access(, 0) == 0);}函数名: acos功能: 反余弦函数用法: double acos(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = acos(x);printf("The arc cosine of %lf is %lf\n", x, result);return 0;}函数名: allocmem功能: 分配DOS存储段用法: int allocmem(unsigned size, unsigned *seg);程序例:#include <dos.h>#include <alloc.h>#include <stdio.h>int main(void){unsigned int size, segp;int stat;size = 64; /* (64 x 16) = 1024 bytes */stat = allocmem(size, &segp);if (stat == -1)printf("Allocated memory at segment: %x\n", segp);elseprintf("Failed: maximum number of paragraphs available is %u\n",stat);return 0;}函数名: arc功能: 画一弧线用法: void far arc(int x, int y, int stangle, int endangle, int radius); 程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int stangle = 45, endangle = 135;int radius = 100;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult(); /* an error occurred */if (errorcode != grOk){printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}midx = getmaxx() / 2;midy = getmaxy() / 2;setcolor(getmaxcolor());/* draw arc */arc(midx, midy, stangle, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: asctime功能: 转换日期和时间为ASCII码用法: char *asctime(const struct tm *tblock);程序例:#include <stdio.h>#include <string.h>#include <time.h>int main(void){struct tm t;char str[80];/* sample loading of tm structure */t.tm_sec = 1; /* Seconds */t.tm_min = 30; /* Minutes */t.tm_hour = 9; /* Hour */t.tm_mday = 22; /* Day of the Month */t.tm_mon = 11; /* Month */t.tm_year = 56; /* Year - does not include century */t.tm_wday = 4; /* Day of the week */t.tm_yday = 0; /* Does not show in asctime */t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime *//* converts structure to null terminatedstring */strcpy(str, asctime(&t));printf("%s\n", str);return 0;}函数名: asin功能: 反正弦函数用法: double asin(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = asin(x);printf("The arc sin of %lf is %lf\n", x, result);return(0);}函数名: assert功能: 测试一个条件并可能使程序终止用法: void assert(int test);程序例:#include <assert.h>#include <stdio.h>#include <stdlib.h>struct ITEM {int key;int value;};/* add item to list, make sure list is not null */ void additem(struct ITEM *itemptr) {assert(itemptr != NULL);/* add item to list */}int main(void){additem(NULL);return 0;}函数名: atan功能: 反正切函数用法: double atan(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = atan(x);printf("The arc tangent of %lf is %lf\n", x, result);return(0);}函数名: atan2功能: 计算Y/X的反正切值用法: double atan2(double y, double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 90.0, y = 45.0;result = atan2(y, x);printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);return 0;}函数名: atexit功能: 注册终止函数用法: int atexit(atexit_t func);程序例:#include <stdio.h>#include <stdlib.h>void exit_fn1(void){printf("Exit function #1 called\n");}void exit_fn2(void){printf("Exit function #2 called\n");}int main(void){/* post exit function #1 */atexit(exit_fn1);/* post exit function #2 */atexit(exit_fn2);return 0;}函数名: atof功能: 把字符串转换成浮点数用法: double atof(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){float f;char *str = "12345.67";f = atof(str);printf("string = %s float = %f\n", str, f);return 0;}函数名: atoi功能: 把字符串转换成长整型数用法: int atoi(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){int n;char *str = "12345.67";n = atoi(str);printf("string = %s integer = %d\n", str, n);return 0;}函数名: atol功能: 把字符串转换成长整型数用法: long atol(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){long l;char *str = "98765432";l = atol(lstr);printf("string = %s integer = %ld\n", str, l);return(0);}BBB.函数名: bar功能: 画一个二维条形图用法: void far bar(int left, int top, int right, int bottom);程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy, i;/* 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;/* loop through the fill patterns */for (i=SOLID_FILL; i<USER_FILL; i++){/* set the fill style */setfillstyle(i, getmaxcolor());/* draw the bar */bar(midx-50, midy-50, midx+50,midy+50);getch();}/* clean up */closegraph();return 0;}函数名: bar3d功能: 画一个三维条形图用法: void far bar3d(int left, int top, int right, int bottom,int depth, int topflag); 程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy, i;/* initialize graphics, 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 error code */}midx = getmaxx() / 2;midy = getmaxy() / 2;/* loop through the fill patterns */for (i=EMPTY_FILL; i<USER_FILL; i++){/* set the fill style */setfillstyle(i, getmaxcolor());/* draw the 3-d bar */bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1);getch();}/* clean up */closegraph();return 0;}函数名: bdos功能: DOS系统调用用法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 程序例:#include <stdio.h>#include <dos.h>/* Get current drive as 'A', 'B', ... */char current_drive(void){char curdrive;/* Get current disk as 0, 1, ... */curdrive = bdos(0x19, 0, 0);return('A' + curdrive);}int main(void){printf("The current drive is %c:\n", current_drive());return 0;}函数名: bdosptr功能: DOS系统调用用法: int bdosptr(int dosfun, void *argument, unsigned dosal); 程序例:#include <string.h>#include <stdio.h>#include <dir.h>#include <dos.h>#include <errno.h>#include <stdlib.h>#define BUFLEN 80int main(void){char buffer[BUFLEN];int test;printf("Enter full pathname of a directory\n");gets(buffer);test = bdosptr(0x3B,buffer,0);if(test){printf("DOS error message: %d\n", errno);/* See errno.h for error listings */exit (1);}getcwd(buffer, BUFLEN);printf("The current directory is: %s\n", buffer);return 0;}函数名: bioscom功能: 串行I/O通信用法: int bioscom(int cmd, char abyte, int port);程序例:#include <bios.h>#include <conio.h>#define COM1 0#define DATA_READY 0x100#define TRUE 1#define FALSE 0#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)int main(void){int in, out, status, DONE = FALSE;bioscom(0, SETTINGS, COM1);cprintf("... BIOSCOM [ESC] to exit ...\n");while (!DONE){status = bioscom(3, 0, COM1);if (status & DATA_READY)if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)putch(out);if (kbhit()){if ((in = getch()) == '\x1B')DONE = TRUE;bioscom(1, in, COM1);}}return 0;}函数名: biosdisk功能: 软硬盘I/O用法: int biosdisk(int cmd, int drive, int head, int track, int sector int nsects, void *buffer);程序例:#include <bios.h>#include <stdio.h>int main(void){int result;char buffer[512];printf("Testing to see if drive a: is ready\n");result = biosdisk(4,0,0,0,0,1,buffer);result &= 0x02;(result) ? (printf("Drive A: Ready\n")) :(printf("Drive A: Not Ready\n"));return 0;}函数名: biosequip功能: 检查设备用法: int biosequip(void);程序例:#include <bios.h>#include <stdio.h>int main(void){int result;char buffer[512];printf("Testing to see if drive a: is ready\n");result = biosdisk(4,0,0,0,0,1,buffer);result &= 0x02;(result) ? (printf("Drive A: Ready\n")) :(printf("Drive A: Not Ready\n"));return 0;}函数名: bioskey功能: 直接使用BIOS服务的键盘接口用法: int bioskey(int cmd);程序例:#include <stdio.h>#include <bios.h>#include <ctype.h>#define RIGHT 0x01#define LEFT 0x02#define CTRL 0x04#define ALT 0x08int main(void){int key, modifiers;/* function 1 returns 0 until a key is pressed */while (bioskey(1) == 0);/* function 0 returns the key that is waiting */key = bioskey(0);/* use function 2 to determine if shift keys were used */ modifiers = bioskey(2);if (modifiers){printf("[");if (modifiers & RIGHT) printf("RIGHT");if (modifiers & LEFT) printf("LEFT");if (modifiers & CTRL) printf("CTRL");if (modifiers & ALT) printf("ALT");printf("]");}/* print out the character read */if (isalnum(key & 0xFF))printf("'%c'\n", key);elseprintf("%#02x\n", key);return 0;函数名: biosmemory功能: 返回存储块大小用法:int biosmemory(void);程序例:#include <stdio.h>#include <bios.h>int main(void){int memory_size;memory_size = biosmemory(); /* returns value up to 640K */printf("RAM size = %dK\n",memory_size);return 0;}函数名: biosprint功能: 直接使用BIOS服务的打印机I/O用法: int biosprint(int cmd, int byte, int port);程序例:#include <stdio.h>#include <conio.h>#include <bios.h>int main(void){#define STATUS 2 /* printer status command */#define PORTNUM 0 /* port number for LPT1 */int status, abyte=0;printf("Please turn off your printer. Press any key to continue\n");getch();status = biosprint(STATUS, abyte, PORTNUM);if (status & 0x01)printf("Device time out.\n");if (status & 0x08)printf("I/O error.\n");if (status & 0x10)printf("Selected.\n");if (status & 0x20)printf("Out of paper.\n");if (status & 0x40)printf("Acknowledge.\n");if (status & 0x80)printf("Not busy.\n");return 0;}函数名: biostime功能: 读取或设置BIOS时间用法: long biostime(int cmd, long newtime);程序例:#include <stdio.h>#include <bios.h>#include <time.h>#include <conio.h>int main(void){long bios_time;clrscr();cprintf("The number of clock ticks since midnight is:\r\n");cprintf("The number of seconds since midnight is:\r\n");cprintf("The number of minutes since midnight is:\r\n");cprintf("The number of hours since midnight is:\r\n");cprintf("\r\nPress any key to quit:");while(!kbhit()){bios_time = biostime(0, 0L);gotoxy(50, 1);cprintf("%lu", bios_time);gotoxy(50, 2);cprintf("%.4f", bios_time / CLK_TCK);gotoxy(50, 3);cprintf("%.4f", bios_time / CLK_TCK / 60);gotoxy(50, 4);cprintf("%.4f", bios_time / CLK_TCK / 3600);}return 0;}函数名: brk功能: 改变数据段空间分配用法: int brk(void *endds);程序例:#include <stdio.h>#include <alloc.h>int main(void){char *ptr;printf("Changing allocation with brk()\n");ptr = malloc(1);printf("Before brk() call: %lu bytes free\n", coreleft());brk(ptr+1000);printf(" After brk() call: %lu bytes free\n", coreleft());return 0;}函数名: bsearch功能: 二分法搜索用法: void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *));程序例:#include <stdlib.h>#include <stdio.h>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))int numarray[] = {123, 145, 512, 627, 800, 933};int numeric (const int *p1, const int *p2){return(*p1 - *p2);}int lookup(int key){int *itemptr;/* The cast of (int(*)(const void *,const void*))is needed to avoid a type mismatch error atcompile time */itemptr = bsearch (&key, numarray, NELEMS(numarray),sizeof(int), (int(*)(const void *,const void *))numeric);return (itemptr != NULL);}int main(void){if (lookup(512))printf("512 is in the table.\n");elseprintf("512 isn't in the table.\n");return 0;}CCC.函数名: cabs功能: 计算复数的绝对值用法: double cabs(struct complex z);程序例:#include <stdio.h>#include <math.h>int main(void){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;}函数名: calloc功能: 分配主存储器用法: void *calloc(size_t nelem, size_t elsize);程序例:#include <stdio.h>#include <alloc.h>int main(void){char *str = NULL;/* allocate memory for string */str = calloc(10, sizeof(char));/* copy "Hello" into string */strcpy(str, "Hello");/* display string */printf("String is %s\n", str);/* free memory */free(str);return 0;}函数名: ceil功能: 向上舍入用法: double ceil(double x);程序例:#include <math.h>#include <stdio.h>int main(void){double number = 123.54;double down, up;down = floor(number);up = ceil(number);printf("original number %5.2lf\n", number);printf("number rounded down %5.2lf\n", down);printf("number rounded up %5.2lf\n", up);return 0;}函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str);程序例:#include <stdio.h>#include <conio.h>int main(void){char buffer[83];char *p;/* There's space for 80 characters plus the NULL terminator */buffer[0] = 81;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);/* Leave room for 5 characters plus the NULL terminator */buffer[0] = 6;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);return 0;}函数名: chdir功能: 改变工作目录用法: int chdir(const char *path);程序例:#include <stdio.h>#include <stdlib.h>#include <dir.h>char old_dir[MAXDIR];char new_dir[MAXDIR];int main(void){if (getcurdir(0, old_dir)){perror("getcurdir()");exit(1);}printf("Current directory is: \\%s\n", old_dir);if (chdir("\\")){perror("chdir()");exit(1);}if (getcurdir(0, new_dir)){perror("getcurdir()");exit(1);}printf("Current directory is now: \\%s\n", new_dir);printf("\nChanging back to orignal directory: \\%s\n", old_dir);if (chdir(old_dir)){perror("chdir()");exit(1);}return 0;}函数名: _chmod, chmod功能: 改变文件的访问方式用法: int chmod(const char *, int permiss);程序例:#include <sys\stat.h>#include <stdio.h>#include <io.h>void make_read_only(char *);int main(void){make_read_only("NOTEXIST.FIL");make_read_only("MY");return 0;}void make_read_only(char *){int stat;stat = chmod(, S_IREAD);if (stat)printf("Couldn't make %s read-only\n", );elseprintf("Made %s read-only\n", );}函数名: chsize功能: 改变文件大小用法: int chsize(int handle, long size);程序例:#include <string.h>#include <fcntl.h>#include <io.h>int main(void){int handle;char buf[11] = "0123456789";/* create text 10 bytes */handle = open("DUMMY.FIL", O_CREAT);write(handle, buf, strlen(buf));/* truncate the 5 bytes in size */chsize(handle, 5);/* close the file */close(handle);return 0;}函数名: circle功能: 在给定半径以(x, y)为圆心画圆用法: void far circle(int x, int y, int radius);程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int 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;setcolor(getmaxcolor());/* draw the circle */circle(midx, midy, radius);/* clean up */getch();closegraph();return 0;}函数名: cleardevice功能: 清除图形屏幕用法: void far cleardevice(void);程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;/* 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;setcolor(getmaxcolor());/* for centering screen messages */settextjustify(CENTER_TEXT, CENTER_TEXT);/* output a message to the screen */outtextxy(midx, midy, "press any key to clear the screen:");/* wait for a key */getch();/* clear the screen */cleardevice();/* output another message */outtextxy(midx, midy, "press any key to quit:");/* clean up */getch();closegraph();return 0;}函数名: clearerr功能: 复位错误标志用法:void clearerr(FILE *stream);程序例:#include <stdio.h>int main(void){FILE *fp;char ch;/* open a writing */fp = fopen("DUMMY.FIL", "w");/* force an error condition by attempting to read */ ch = fgetc(fp);printf("%c\n",ch);if (ferror(fp)){/* display an error message */printf("Error reading from DUMMY.FIL\n");/* reset the error and EOF indicators */clearerr(fp);}fclose(fp);return 0;}函数名: clearviewport功能: 清除图形视区用法: void far clearviewport(void);程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#define CLIP_ON 1 /* activates clipping in viewport */int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int ht;/* 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 */}setcolor(getmaxcolor());ht = textheight("W");/* message in default full-screen viewport */outtextxy(0, 0, "* <-- (0, 0) in default viewport");/* create a smaller viewport */setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);/* display some messages */outtextxy(0, 0, "* <-- (0, 0) in smaller viewport");outtextxy(0, 2*ht, "Press any key to clear viewport:");/* wait for a key */getch();/* clear the viewport */clearviewport();/* output another message */outtextxy(0, 0, "Press any key to quit:");/* clean up */getch();closegraph();return 0;}函数名: _close, close功能: 关闭文件句柄用法: int close(int handle);程序例:#include <string.h>#include <stdio.h>#include <fcntl.h>#include <io.h>main(){int handle;char buf[11] = "0123456789";/* create a 10 bytes */handle = open("NEW.FIL", O_CREAT);if (handle > -1){write(handle, buf, strlen(buf));/* close the file */close(handle);}else{printf("Error opening file\n");}return 0;}函数名: clock功能: 确定处理器时间用法: clock_t clock(void);程序例:#include <time.h>#include <stdio.h>#include <dos.h>int main(void){clock_t start, end;start = clock();delay(2000);end = clock();printf("The time was: %f\n", (end - start) / CLK_TCK);return 0;}函数名: closegraph功能: 关闭图形系统用法: void far closegraph(void);程序例:#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, y;/* initialize graphics mode */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an erroroccurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}x = getmaxx() / 2;y = getmaxy() / 2;/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT);outtextxy(x, y, "Press a key to close the graphics system:");/* wait for a key */getch();/* closes down the graphics system */closegraph();printf("We're now back in text mode.\n");printf("Press any key to halt:");getch();return 0;}函数名: clreol功能: 在文本窗口中清除字符到行末用法: void clreol(void);程序例:#include <conio.h>int main(void){clrscr();cprintf("The function CLREOL clears all characters from the\r\n");cprintf("cursor position to the end of the line within the\r\n");cprintf("current text window, without moving the cursor.\r\n");cprintf("Press any key to continue . . .");gotoxy(14, 4);getch();clreol();getch();return 0;}函数名: clrscr功能: 清除文本模式窗口用法: void clrscr(void);程序例:#include <conio.h>int main(void){int i;clrscr();for (i = 0; i < 20; i++)cprintf("%d\r\n", i);cprintf("\r\nPress any key to clear screen");getch();clrscr();cprintf("The screen has been cleared!");getch();return 0;}函数名: coreleft功能: 返回未使用内存的大小用法: unsigned coreleft(void);程序例:#include <stdio.h>#include <alloc.h>int main(void){printf("The difference between the highest allocated block and\n");printf("the top of the heap is: %lu bytes\n", (unsigned long) coreleft());return 0;}函数名: cos功能: 余弦函数用法: double cos(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = cos(x);printf("The cosine of %lf is %lf\n", x, result);return 0;}函数名: cosh功能: 双曲余弦函数用法: dluble cosh(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = cosh(x);printf("The hyperboic cosine of %lf is %lf\n", x, result);return 0;}函数名: country功能: 返回与国家有关的信息用法: struct COUNTRY *country(int countrycode, struct country *country); 程序例:。
c语言常用函数

bc mp(比较内存内容)相关函数b cmp,s trcas ecmp,strcm p,str coll,strnc mp,st rncas ecmp表头文件 #i nclud e<str ing.h>定义函数int b cmp ( cons t voi d *s1,cons t voi d * s2,int n);函数说明 bc mp()用来比较s1和s2所指的内存区间前n个字节,若参数n为0,则返回0。
返回值若参数s1 和s2所指的内存内容都完全相同则返回0 值,否则返回非零值。
附加说明建议使用memc mp()取代。
范例参考memc mp()。
bco py(拷贝内存内容)相关函数m emccp y,mem cpy,m emmov e,str cpy,c trncp y表头文件#incl ude <strin g.h>定义函数 vo id bc opy ( cons t voi d *sr c,voi d *de st ,i nt n);函数说明bcopy()与me mcpy()一样都是用来拷贝s rc所指的内存内容前n个字节到dest所指的地址,不过参数s rc与de st在传给函数时是相反的位置。
返回值附加说明建议使用memc py()取代范例 #i nclud e<str ing.h>mai n(){char dest[30]=”stri ng(a)”;ch ar sr c[30]=”str ing\0strin g”;i nt i;bcop y(src,dest,30);/* sr c指针放在前*/p rintf(bcop y():“)fo r(i=0;i<30;i++)prin tf(“%c”,de st[i]);me mcpy(destsrc,30); /*dest指针放在钱*/pr intf(…\nme mcpy() : “);fo r(i=0;i<30;i++)prin tf(“%c”,de st[i]);执行b copy() : s tring stri ngme mcpy() :st ringsringbze ro(将一段内存内容全清为零)相关函数m emset,swab表头文件#inclu de<st ring.h>定义函数 void bzer o(voi d *s,int n);函数说明 bzer o()会将参数s所指的内存区域前n个字节,全部设为零值。
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语言提供了丰富的文件操作函数,可以实现对文件的读取、写入、关闭等操作。
下面是一些常用的文件操作函数的介绍:1. fopen(函数:用于打开一个文件,并返回一个指向该文件的文件指针。
函数原型为:FILE *fopen(const char *filename, const char*mode)。
filename为要打开的文件名,mode为打开方式,包括读取("r")、写入("w")、追加("a")等。
2. fclose(函数:用于关闭一个文件,释放文件指针所占用的资源。
函数原型为:int fclose(FILE *stream)。
stream为指向要关闭文件的指针。
3. fread(函数:用于从文件中读取数据,并将读取得到的数据存储在指定的内存区域中。
函数原型为:size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)。
ptr为存储读取数据的内存区域的指针,size为每个数据项的大小,nmemb为要读取的数据项的个数,stream为要读取数据的文件指针。
4. fwrite(函数:用于将数据写入到文件中。
函数原型为:size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)。
ptr为要写入的数据的内存区域的指针,size为每个数据项的大小,nmemb为要写入的数据项的个数,stream为要写入数据的文件指针。
5. fprintf(函数:用于向文件中写入格式化的数据。
函数原型为:int fprintf(FILE *stream, const char *format, ...)。
stream为要写入数据的文件指针,format为格式化字符串,后面可以跟上需要写入的数据。
C语言标准库函数大全.pdf

C语言标准库函数大全.pdf1、ArthersBlog博客园社区首页新随笔联系管理订阅随笔-208文章-0评论-14TurboC2.0函数中文说明大全分类函数,所在函数库为ctype.hintisalpha(intch)若ch是字母(A-Z,a-z)返回非0值,否则返回0intisalnum(intch)若ch是字母(A-Z,a-z)或数字(0-9),返回2、非0值,否则返回0intisascii(intch)若ch是字符(ASCII码中的0-127)返回非0值,否则返回0intiscntrl(intch)若ch是作废字符(0x7F)或一般掌握字符(0x00-0x1F),返回非0值,否则返回0intisdigit(intch)若ch是数字(0-9)返回非0值,否则返回0intisgraph(intch)若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0intislower(intch)若ch是小写字母(a-z3、)返回非0值,否则返回0intisprint(intch)若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0intispunct(intch)若ch是标点字符(0x00-0x1F)返回非0值,否则返回0intisspace(intch)若ch是空格(),水平制表符(t),回车符(r),走纸换行(f),垂直制表符(v),换行符(n),返回非0值,否则返回0intisupper(intch)若ch是大写4、字母(A-Z)返回非0值,否则返回0intisxdigit(intch)若ch 是16进制数(0-9,A-F,a-f)返回非0值,否则返回0inttolower(intch)若ch是大写字母(A-Z)返回相应的小写字母(a-z)inttoupper(intch)若ch是小写字母(5、a-z)返回相应的大写字母(A-Z)数学函数,所在函数库为math.h、stdlib.h、string.h、float.hintabs(inti)返回整型参数i的肯定值doublecabs(structcomplexznum)返回复数znum的肯定值doublefabs(doublex)返回双精度参数x的肯定值longlabs(longn)返回长整型参数n的肯定值doubleexp(doublex)返回指数函数ex的值doublefrexp(doublevalue,int*eptr)返回v6、alue=x*2n中x的值,n存贮在eptr中doubleldexp(doublevalue,intexp);返回value*2exp的值doublelog(doublex)返回logex的值doublelog10(doublex)返回log10x的值doublepow(doublex,doubley)返回xy的值doublepow10(intp)返回10p的值doublesqrt(doublex)返回x的开方doubleacos(doublex)返回x的反余弦cos-1(x)值,x为弧度c语言库函数大全--资料收集预备是胜利的首要前提与我联系发短消息搜寻常用链接我的随笔7、我的空间我的短信我的评论更多链接留言簿给我留言查看留言随笔分类(174).Net(rss)Algorithm(15)(rss)Basic(10)(rss)CC++(33)(rss) DBase(2)(rss)Essay(112)(rss)Java(2)(rss)随笔档案(208)2021年8月(1)2021年5月(5)2021年4月(4)2021年3月(1)2021年1月(21)2021年12月(48)2021年11月(121)2021年10月(7)找找看Page1of222021-4-3file://F:DOCUME~1lichaoLOCALS~1Tem8、pKABU69VF.htm。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
getch(); returnph
功能: 通过检测硬件确定图形驱动程序和模式
用法: void far detectgraph(int far *graphdriver, int far *graphmode);
程序例:
#include #include #include #include /* names of the various cards supported */ char *dname[] = { "requests detection", "a CGA", "an MCGA", "an EGA", "a 64K EGA", "a monochrome EGA", "an IBM 8514", "a Hercules monochrome", "an AT&T 6300 PC", "a VGA", "an IBM 3270 PC" }; int main(void) { /* returns detected hardware info. */ int gdriver, gmode, errorcode; /* detect graphics hardware available */ detectgraph(&gdriver, &gmode); /* read result of detectgraph call */ 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
函数名: dup
函数名: delline
功能: 在文本窗口中删去一行
用法: void delline(void);
程序例:
#include int main(void) { clrscr(); cprintf("The function DELLINE deletes \ the line containing the\r\n"); cprintf("cursor and moves all lines \ below it one line up.\r\n"); cprintf("DELLINE operates within the \ currently active text\r\n"); cprintf("window. Press any key to \ continue . . ."); gotoxy(1,2); /* Move the cursor to the second line and first column */ getch(); delline();
函数名: div
功能: 将两个整数相除, 返回商和余数
用法: div_t (int number, int denom);
程序例:
# include #include div_t x; int main(void) { x = div(10,3); printf("10 div 3 = %d remainder %d\n", x.quot, x.rem); return 0; }
函数名: disable
功能: 屏蔽中断
用法: void disable(void);
程序例:
/***NOTE: This is an interrupt service routine. You cannot compile this program with Test Stack Overflow turned on and get an executable file that operates correctly. */ #include #include #include #define INTR 0X1C /* The clock tick interrupt */ void interrupt ( *oldhandler)(void); int count=0; void interrupt handler(void) { /* disable interrupts during the handling of the interrupt */ disable(); /* increase the global counter */ count++; /* reenable interrupts at the end of the handler */ enable(); /* call the old routine */ oldhandler(); } int main(void) { /* save the old interrupt vector */ oldhandler = getvect(INTR); /* install the new interrupt handler */ setvect(INTR, handler); /* loop until the counter exceeds 20 */ while (count < 20) printf("count is %d\n",count); /* reset the old interrupt handler */ setvect(INTR, oldhandler); return 0; }
函数名: drawpoly
功能: 画多边形
用法: void far drawpoly(int numpoints, int far *polypoints);
程序例:
#include #include #include #include int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int maxx, maxy; /* our polygon array */ int poly[10]; /* 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(); /* terminate with an error code */ exit(1); } maxx = getmaxx(); maxy = getmaxy(); poly[0] = 20; /* 1st vertext */ poly[1] = maxy / 2; poly[2] = maxx - 20; /* 2nd */ poly[3] = 20; poly[4] = maxx - 50; /* 3rd */ poly[5] = maxy - 20; poly[6] = maxx / 2; /* 4th */ poly[7] = maxy / 2; /* drawpoly doesn't automatically close the polygon, so we close it. */ poly[8] = poly[0]; poly[9] = poly[1]; /* draw the polygon */ drawpoly(5, poly); /* clean up */ getch(); closegraph(); return 0; }
code */ } /* display the information detected */ clrscr(); printf("You have %s video display \ card.\n", dname[gdriver]); printf("Press any key to halt:"); getch(); return 0; }
C 语言函数大全(d 开头)
函数名: delay
功能: 将程序的执行暂停一段时间(毫秒)
用法: void delay(unsigned milliseconds);
程序例:
/* Emits a 440-Hz tone for 500 milliseconds */ #include int main(void) { sound(440); delay(500); nosound(); return 0; }
函数名: difftime
功能: 计算两个时刻之间的时间差
用法: double difftime(time_t time2, time_t time1);
程序例:
#include #include #include #include int main(void) { time_t first, second; clrscr(); first = time(NULL); /* Gets system time */ delay(2000); /* Waits 2 secs */ second = time(NULL); /* Gets system time again */ printf("The difference is: %f \ seconds\n",difftime(second,first)); getch(); return 0; }