C语言函数大全(h开头)
C语言头文件大全

标准C语言头文件ISO C标准定义的头文件(24项)<assert。
h> 验证程序断言〈complex。
h〉支持复数算术运算〈ctype。
h〉字符类型<errno。
h〉出错码<fenv。
h> 浮点环境〈float。
h> 浮点常量<inttypes。
h> 整型格式转换〈iso646.h〉替代关系操作符宏〈limits。
h> 实现常量<locale.h〉局部类别<math。
h〉数学常量〈setjmp.h> 非局部goto〈signal。
h> 信号〈stdarg。
h〉可变参数表〈stdbool.h> 布尔类型和值〈stddef。
h> 标准定义〈stdint.h〉整型<stdio。
h〉标准I/O库〈stdlib.h〉实用程序库函数〈string。
h〉字符串操作<tgmath.h〉通用类型数学宏<time.h> 时间和日期〈wchar。
h〉宽字符支持〈wctype.h〉宽字符分类和映射支持POSIX标准定义的必须的头文件(26项)〈dirent.h〉目录项<fcntl.h> 文件控制〈fnmatch。
h> 文件名匹配类型〈glob。
h> 路径名模式匹配类型〈grp。
h> 组文件〈netdb.h> 网络数据库操作〈pwd.h〉口令文件<regex。
h> 正则表达式〈tar。
h> tar归档值<termios。
h> 终端I/O <unistd.h> 符号常量<utime.h〉文件时间<wordexp。
h〉字扩展类型<arpa/inet.h> Internet定义<net/if.h> 套接字本地接口〈netinet/in.h> Internet地址族 <netinet/tcp.h〉传输控制协议〈sys/mman。
C语言头文件大全

精心整理标准C语言头文件ISOC标准定义的头文件(24项)<assert.h>验证程序断言<complex.h>?支持复数算术运算<ctype.h>?字符类型<errno.h>?出错码<fenv.h>?浮点环境<float.h>?浮点常量<inttypes.h>?整型格式转换<iso646.h>替代关系操作符宏<limits.h>?实现常量<locale.h>?局部类别<math.h>?数学常量<setjmp.h>非局部goto<signal.h>?信号<stdarg.h>?可变参数表<stdbool.h>?布尔类型和值POSIX<pwd.h>POSIX<ftw.h>?<strings.h>?字符串操作<syslog.h>?系统出错日志记录<ucontext.h>?用户上下文<ulimit.h>?用户限制<utmpx.h>?用户帐户数据库<sys/ipc.h>IPC<sys/msg.h>?消息队列<sys/resource.h>资源操作<sys/sem.h>?信号量<sys/shm.h>?共享存储<sys/statvfs.h>?文件系统信息<sys/time.h>?时间类型<sys/timeb.h>?附加的时间<sys/uio.h>?矢量I/O操作POSIX标准定义的可选头文件(8项)<aio.h>?异步I/O <mqueue.h>?消息队列<pthread.h>?线程<sched.h>?执行调度<semaphore.h>信号量<spawn.h>?实时spawn接口<stropts.h>?XSISTREAMS接口<trace.h>?时间跟踪标准C++语言头文件(54个其中16个用于构建STL,3个为附加非必须)<algorithm>STL通用算法<bitset>STL位集容器<cassert>?用于在程序运行时执行断言<cctype>字符处理<cerrno>错误码<cfloat>?用于测试浮点类型属性<ciso646>?ISO646变体字符集<climits>?测试整数类型属性<clocale>本地化函数<cmath> 数学函数<complex>复数类<csetjmp>?执行非内部的goto语句<csignal>?信号<cstdarg>?访问参数数量变化的函数<cstddef>?用于定义实用的类型和宏<cstdio>输入/输出<cstdlib>杂项函数及内存分配<cstring>字符串<ctime> 时间<cwchar>宽字符处理及输入/输出<cwctype>宽字符分类<deque>STL双端队列容器<exception>异常处理类<fstream>文件流TheStandardC++libraryconsistsof51requiredheaders.Thisimplementationalsoincludesthreeadditional headers,<hash_map>,<hash_set>,and<slist>,notrequiredbytheC++Standard,foratotalof54headers.Ofth ese54headers,16constitutetheStandardTemplateLibrary,orSTL.Theseareindicatedbelowwiththenotatio n<algorithm>--(STL)fordefiningnumeroustemplatesthatimplementusefulalgorithms<bitset> --fordefiningatemplateclassthatadministerssetsofbits<complex> --fordefiningatemplateclassthatsupportscomplexarithmetic<deque>--(STL)fordefiningatemplateclassthatimplementsadequecontainer<exception>--fordefiningseveralfunctionsthatcontrolexceptionhandling<fstream> --fordefiningseveraliostreamstemplateclassesthatmanipulateexteralfiles<functional>--(STL)fordefiningseveraltemplatesthathelpconstructpredicatesfor<ios>defined<list><map><memory><new><queue><set><slist>--(STL)fordefiningatemplateclassthatimplementsasinglylinkedlistcontainer<sstream>--fordefiningseveraliostreamstemplateclassesthatmanipulatestringcontainers<stack>--(STL)fordefiningatemplateclassthatimplementsastackcontainer<stdexcept>--fordefiningseveralclassesusefulforreportingexceptions<streambuf>--fordefiningtemplateclassesthatbufferiostreamsoperations<string> --fordefiningatemplateclassthatimplementsastringcontainer<strstream>--fordefiningseveraliostreamsclassesthatmanipulatein-memorycharactersequences<typeinfo> --fordefiningclasstype_info,theresultofthetypeidoperator<utility>--(STL)fordefiningseveraltemplatesofgeneralutility<valarray> --fordefiningseveralclassesandtemplateclassesthatsupportvalue-orientedarrays<vector>--(STL)fordefiningatemplateclassthatimplementsavectorcontainer新的C标准库<cassert> --forenforcingassertionswhenfunctionsexecute<cctype> --forclassifyingcharacters<cerrno> --fortestingerrorcodesreportedbylibraryfunctions<cfloat> --fortestingfloating-pointtypeproperties<ciso646> --forprogramminginISO646variantcharactersets<climits> --fortestingintegertypeproperties<clocale> --foradaptingtodifferentculturalconventions<cmath> --forcomputingcommonmathematicalfunctions<ctime>旧的C<stdlib.h> --forperformingavarietyofoperations<string.h> --formanipulatingseveralkindsofstrings<time.h> --forconvertingbetweenvarioustimeanddateformats<wchar.h> --formanipulatingwidestreamsandseveralkindsofstrings<wctype.h> --forclassifyingwidecharactersFinally,inthisimplementation,theStandardC++libraryalsoincludesseveralheadersforcompatibilitywi thtraditionalC++libraries:<fstream.h>--fordefiningseveraliostreamstemplateclassesthatmanipulateexteralfiles<iomanip.h>--fordeclaringseveraliostreamsmanipulatorsthattakeanargument<iostream.h>--fordeclaringtheiostreamsobjectsthatmanipulatethestandardstreams<new.h> --fordeclaringseveralfunctionsthatallocateandfreestorage<stl.h> --fordeclaringseveraltemplateclassesthataidmigrationfromolderversions oftheStandardTemplateLibrary。
(完整word版)C语言函数用法大全

函数名: stpcpy功能: 拷贝一个字符串到另一个用法: char *stpcpy(char *destin, char *source); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";stpcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcat功能: 字符串拼接函数用法: char *strcat(char *destin, char *source); 程序例:#include <string.h>#include <stdio.h>int main(void){char destination[25];char *blank = " ", *c = "C++", *Borland = "Borland";strcpy(destination, Borland);strcat(destination, blank);strcat(destination, c);printf("%s\n", destination);return 0;}函数名: strchr功能: 在一个串中查找给定字符的第一个匹配之处\用法: char *strchr(char *str, char c);程序例:#include <string.h>#include <stdio.h>{char string[15];char *ptr, c = 'r';strcpy(string, "This is a string");ptr = strchr(string, c);if (ptr)printf("The character %c is at position: %d\n", c, ptr-string);elseprintf("The character was not found\n");return 0;}函数名: strcmp功能: 串比较用法: int strcmp(char *str1, char *str2);看Asic码,str1>str2,返回值> 0;两串相等,返回0程序例:#include <string.h>#include <stdio.h>{char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";int ptr;ptr = strcmp(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strcmp(buf2, buf3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return 0;}函数名: strncmpi功能: 将一个串中的一部分与另一个串比较, 不管大小写用法: int strncmpi(char *str1, char *str2, unsigned maxlen); 程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)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;}函数名: strcpy功能: 串拷贝用法: char *strcpy(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";strcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcspn功能: 在串中查找第一个给定字符集内容的段用法: int strcspn(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "747DC8";int length;length = strcspn(string1, string2);printf("Character where strings intersect is at position %d\n", length);return 0;}函数名: strdup功能: 将串拷贝到新建的位置处用法: char *strdup(char *str);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *dup_str, *string = "abcde";dup_str = strdup(string);printf("%s\n", dup_str);free(dup_str);return 0;}函数名: stricmp功能: 以大小写不敏感方式比较两个串用法: int stricmp(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = stricmp(buf2, buf1);if (ptr > 0)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;}函数名: strerror功能: 返回指向错误信息字符串的指针用法: char *strerror(int errnum);程序例:#include <stdio.h>#include <errno.h>int main(void){char *buffer;buffer = strerror(errno);printf("Error: %s\n", buffer);return 0;}函数名: strcmpi功能: 将一个串与另一个比较, 不管大小写用法: int strcmpi(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)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;}函数名: strncmp功能: 串比较用法: int strncmp(char *str1, char *str2, int maxlen);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";int ptr;ptr = strncmp(buf2,buf1,3);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strncmp(buf2,buf3,3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return(0);}函数名: strncmpi功能: 把串中的一部分与另一串中的一部分比较, 不管大小写用法: int strncmpi(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strncmpi(buf2,buf1,3);if (ptr > 0)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;}函数名: strncpy功能: 串拷贝用法: char *strncpy(char *destin, char *source, int maxlen); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";strncpy(string, str1, 3);string[3] = '\0';printf("%s\n", string);return 0;}函数名: strnicmp功能: 不注重大小写地比较两个串用法: int strnicmp(char *str1, char *str2, unsigned maxlen); 程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strnicmp(buf2, buf1, 3);if (ptr > 0)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;}函数名: strnset功能: 将一个串中的所有字符都设为指定字符用法: char *strnset(char *str, char ch, unsigned n); 程序例:#include <stdio.h>#include <string.h>int main(void){char *string = "abcdefghijklmnopqrstuvwxyz";char letter = 'x';printf("string before strnset: %s\n", string);strnset(string, letter, 13);printf("string after strnset: %s\n", string);return 0;}函数名: strpbrk功能: 在串中查找给定字符集中的字符用法: char *strpbrk(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>int main(void){char *string1 = "abcdefghijklmnopqrstuvwxyz";char *string2 = "onm";char *ptr;ptr = strpbrk(string1, string2);if (ptr)printf("strpbrk found first character: %c\n", *ptr);elseprintf("strpbrk didn't find character in set\n");return 0;}函数名: strrchr功能: 在串中查找指定字符的最后一个出现用法: char *strrchr(char *str, char c);程序例:#include <string.h>#include <stdio.h>int main(void){char string[15];char *ptr, c = 'r';strcpy(string, "This is a string");ptr = strrchr(string, c);if (ptr)printf("The character %c is at position: %d\n", c, ptr-string);elseprintf("The character was not found\n");return 0;}函数名: strrev功能: 串倒转用法: char *strrev(char *str);程序例:#include <string.h>#include <stdio.h>int main(void){char *forward = "string";printf("Before strrev(): %s\n", forward);strrev(forward);printf("After strrev(): %s\n", forward);return 0;}函数名: strset功能: 将一个串中的所有字符都设为指定字符用法: char *strset(char *str, char c);程序例:#include <stdio.h>#include <string.h>int main(void){char string[10] = "123456789";char symbol = 'c';printf("Before strset(): %s\n", string);strset(string, symbol);printf("After strset(): %s\n", string);return 0;}函数名: strspn功能: 在串中查找指定字符集的子集的第一次出现用法: int strspn(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "123DC8";int length;length = strspn(string1, string2);printf("Character where strings differ is at position %d\n", length);return 0;}函数名: strstr功能: 在串中查找指定字符串的第一次出现用法: char *strstr(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>int main(void){char *str1 = "Borland International", *str2 = "nation", *ptr;ptr = strstr(str1, str2);printf("The substring is: %s\n", ptr);return 0;}函数名: strtod功能: 将字符串转换为double型值用法: double strtod(char *str, char **endptr);程序例:#include <stdio.h>#include <stdlib.h>int main(void){char input[80], *endptr;double value;printf("Enter a floating point number:");gets(input);value = strtod(input, &endptr);printf("The string is %s the number is %lf\n", input, value);return 0;}函数名: strtok功能: 查找由在第二个串中指定的分界符分隔开的单词用法: char *strtok(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char input[16] = "abc,d";char *p;/* strtok places a NULL terminatorin front of the token, if found */p = strtok(input, ",");if (p) printf("%s\n", p);/* A second call to strtok using a NULLas the first parameter returns a pointerto the character following the token */p = strtok(NULL, ",");if (p) printf("%s\n", p);return 0;}函数名: strtol功能: 将串转换为长整数用法: long strtol(char *str, char **endptr, int base); 程序例:#include <stdlib.h>#include <stdio.h>int main(void){char *string = "87654321", *endptr;long lnumber;/* strtol converts string to long integer */lnumber = strtol(string, &endptr, 10);printf("string = %s long = %ld\n", string, lnumber);return 0;}函数名: strupr功能: 将串中的小写字母转换为大写字母用法: char *strupr(char *str);程序例:#include <stdio.h>#include <string.h>int main(void){char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;/* converts string to upper case characters */ptr = strupr(string);printf("%s\n", ptr);return 0;}函数名: swab功能: 交换字节用法: void swab (char *from, char *to, int nbytes); 程序例:#include <stdlib.h>#include <stdio.h>#include <string.h>char source[15] = "rFna koBlrna d";char target[15];int main(void){swab(source, target, strlen(source));printf("This is target: %s\n", target);return 0;}。
C语言字符串函数大全

今天总结了下C语言字符串函数。
C语言字符串函数总结:1.字符处理库(ctype)中的函数2.stdio中的字符串和字符输入/输出的函数3.通用实用库stdlib中的字符串转换函数4.字符串处理库string中的字符串处理函数C语言的字符串实际上是存储单个字符的数组,结尾包含一个结束该字符串的特别的字符("空字符",用'\0'表示)。
char string1[]="first"实际上有6个元素。
char color="blue" char * p="blue"注意p[i]不能修改,若需修改应用字符数组。
一、.字符处理库(ctype)中的函数#include<ctype.h>函数原型:int f(int c)isdigit, isalpha, isalnum, isxdigit, islower, isupper, tolower, toupper, isspace,空白字符:新行符\n, 空格,回车''\r",水平制表符"\t", 垂直制表符"\v" isctrl, ispunct, isprint, isalpha二、stdio中的字符串和字符输入/输出的函数int getchar(void) 从标准输入设备读取字符以整数返回char * get(char * s) 从标准输入设备读入字符到数组s直到遇到新行符和文件结束符为止,然后再数组后追加NULL字符int putchar(int c) 打印字符int puts(const char * s) 打印字符串s和新行符int sprintf(char * s, const char * format) 与printf区别在于输出结果存放在s中int sscanf(char * s, const char * format); 与scanf区别在于从数组s读取数据示例1 字符串反转#include <stdio.h> void reverse(char *s) {if(s[0] == '\0') return;else{reverse(&s[1]); putchar(s[0]);}}int main(){char s[100];gets(s);reverse(s);return 0;}输入:sf输出:fs示例2 sscanf和sprintf #include<stdio.h>int main(){int x=1;double y=2.1;char s[100];sprintf(s,"Hello!%d, %f", x, y);puts(s);sscanf(s,"%d%f",&x,&y);printf("x:%d, y:%f", x, y);return 0;}输出:Hello!1, 2.100000x:1, y:2.100000三、stdlib中的字符串转换函数#include<stdlib.h>1. atoi(将字符串转换成整型数)定义函数int atoi(const char *nptr); 函数说明atoi()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时('\0')才结束转换,并将结果返回。
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语言函数库目录第一章(C标准库) (8)1. <assert.h>:诊断 (8)2. <ctype.h>:字符类别测试 (9)3. <errno.h>:错误处理 (10)4. <limits.h>:整型常量 (11)5. <locale.h>:地域环境 (12)6. <math.h>:数学函数 (14)7. <setjmp.h>:非局部跳转 (15)8. <signal.h>:信号 (17)9. <stdarg.h>:可变参数表 (20)10. <stddef.h>:公共定义 (21)11. <stdio.h>:输入输出 (22)12. <stdlib.h>:实用函数 (24)13. <time.h>:日期与时间函数 (25)第二章(IO函数) (27)clearerr:复位错误标志函数 (29)feof:检测文件结束符函数 (30)ferror:检测流上的错误函数 (31)fflush:清除文件缓冲区函数 (32)fgetpos:取得当前文件的句柄函数 (35)fgets:从流中读取字符串函数 (36)fopen、fclose:文件的打开与关闭函数 (37)fprintf:格式化输出函数 (39)fputc:向流中输出字符函数 (41)fputs:向流中输出字符串函数 (41)fread:从流中读取字符串函数 (42)freopen:替换文件中数据流函数 (43)fscanf:格式化输入函数 (44)fseek:文件指针定位函数 (45)fsetpos:定位流上的文件指针函数 (47)ftell:返回当前文件指针位置函数 (48)fwrite:向文件写入数据函数 (49)getc:从流中读取字符函数 (50)getchar:从标准输入文件中读取字符函数 (51)gets:从标准输入文件中读取字符串函数 (52)perror:打印系统错误信息函数 (53)printf:产生格式化输出的函数 (54)putc:向指定流中输出字符函数 (54)putchar:向标准输出文件上输出字符 (56)puts:将字符串输出到终端函数 (56)rename:重命名文件函数 (58)rewind:重置文件指针函数 (59)scanf:格式化输入函数 (60)setbuf、setvbuf:指定文件流的缓冲区函数 (61)sprintf:向字符串写入格式化数据函数 (62)sscanf:从缓冲区中读格式化字符串函数 (63)tmpfile:创建临时文件函数 (64)tmpnam:创建临时文件名函数 (65)ungetc:把字符退回到输入流函数 (66)第三章(字符处理函数) (68)isalnum:检查字符是否是字母或数字 (68)isalpha:检查字符是否是字母 (69)isascii:检查字符是否是ASCII码 (70)iscntrl:检查字符是否是控制字符 (71)isdigit:检查字符是否是数字字符 (72)isgraph:检查字符是否是可打印字符(不含空格) (73)islower:检查字符是否是小写字母 (74)isprint:检查字符是否是可打印字符(含空格) (75)ispunct:检查字符是否是标点字符 (75)isspace:检查字符是否是空格符 (76)isupper:检查字符是否是大写字母 (77)isxdigit:检查字符是否是十六进制数字字符 (78)toascii:将字符转换为ASCII码 (79)tolower:将大写字母转换为小写字母 (80)toupper:将小写字母转换为大写字母 (80)第四章(字符串函数) (81)atof:字符串转浮点型函数 (83)atoi:字符串转整型函数 (84)atol:字符串转长整型函数 (85)memchr:字符搜索函数 (85)memcmp:字符串比较函数 (86)memcpy:字符串拷贝函数 (87)memmove:字块移动函数 (89)memset:字符加载函数 (90)strcat:字符串连接函数 (91)strchr:字符串中字符首次匹配函数 (92)strcmp:字符串比较函数 (93)strcpy:字符串拷贝函数 (95)strcspn:字符集逆匹配函数 (96)strdup:字符串新建拷贝函数 (97)strerror:字符串错误信息函数 (98)strlen:计算字符串长度函数 (99)strlwr:字符串小写转换函数 (100)strncmp:字符串子串比较函数 (102)strncpy:字符串子串拷贝函数 (103)strpbrk:字符集字符匹配函数 (104)strrchr:字符串中字符末次匹配函数 (106)strrev:字符串倒转函数 (107)strset:字符串设定函数 (108)strspn:字符集匹配函数 (109)strstr:字符串匹配函数 (110)strtod:字符串转换成双精度函数 (111)strtok:字符串分隔函数 (112)strtol:字符串转换成长整型函数 (114)strtoul:字符串转换成无符号长整型函数 (115)strupr:字符串大写转换函数 (116)strupr:字符串大写转换函数 (117)第五章(数学函数) (118)abs、labs、fabs:求绝对值函数 (119)acos:反余弦函数 (120)asin:反正弦函数 (121)atan:反正切函数 (122)atan2:反正切函数2 (122)ceil:向上舍入函数 (123)cosh:双曲余弦函数 (124)div、ldiv:除法函数 (125)exp:求e的x次幂函数 (126)floor:向下舍入函数 (127)fmod:求模函数 (128)frexp:分解浮点数函数 (128)hypot:求直角三角形斜边长函数 (129)ldexp:装载浮点数函数 (130)log、log10:对数函数 (130)modf:分解双精度数函数 (131)pow、pow10:指数函数 (132)rand:产生随机整数函数 (133)sin:正弦函数 (134)sinh:双曲正弦函数 (134)sqrt:开平方函数 (135)srand:设置随机时间的种子函数 (135)tan:正切函数 (136)tanh:双曲正切函数 (137)第六章(时间和日期函数) (138)asctime:日期和时间转换函数 (138)clock:测定运行时间函数 (139)difftime:计算时间差函数 (141)gmtime:将日历时间转换为GMT (142)localtime:把日期和时间转变为结构 (143)mktime:时间类型转换函数 (144)time:获取系统时间函数 (145)第七章(其它函数) (146)abort:异常终止进程函数 (147)atexit:注册终止函数 (147)bsearch:二分搜索函数 (148)calloc:分配主存储器函数 (150)exit:正常终止进程函数 (151)free:释放内存函数 (152)getenv:获取环境变量 (153)malloc:动态分配内存函数 (154)qsort:快速排序函数 (155)realloc:重新分配主存函数 (156)第一章(C标准库)1. <assert.h>:诊断2. <ctype.h>:字符类别测试3. <errno.h>:错误处理4. <limits.h>:整型常量5. <locale.h>:地域环境6. <math.h>:数学函数7. <setjmp.h>:非局部跳转8. <signal.h>:信号9. <stdarg.h>:可变参数表10. <stddef.h>:公共定义11. <stdio.h>:输入输出12. <stdlib.h>:实用函数13. <time.h>:日期与时间函数1. <assert.h>:诊断<assert.h>中只定义了一个带参的宏assert,其定义形式如下:void assert (int 表达式)assert宏用于为程序增加诊断功能,它可以测试一个条件并可能使程序终止。
C语言头文件大全
正弦 sin
正切 tan
双曲函数 双曲余弦 cosh
双曲正弦 sinh
双曲正切 tanh
指数和对数
指数函数 exp
指数分解函数 frexp
乘积指数函数 fdexp
自然对数 log
以10为底的对数 log10
浮点数分解函数 modf
得到时间 time
时间转换函数
得到以ASCII码表示的时间 asctime
得到字符串表示的时间 ctime
得到指定格式的时间 strftime
函数库未来的发展方向
本部分用于说明各类别函数库在将来如何发展。
序号 库类别 头文件 详细说明
1 错误处理 errno.h
#include <ctype.h> //字符处理
#include <errno.h> //定义错误码
#include <float.h> //浮点数处理
#include <fstream.h> //文件输入/输出
#include <iomanip.h> //参数化输入/输出
本类别的函数用于处理不同国家的语言差异。
2 头文件 local.h
函数列表
函数类别 函数用途 详细说明
地区控制
地区设置 setlocale
数字格式约定查询
国家的货币、日期、时间等的格式转换 localeconv
数学函数
本分类给出了各种数学计算函数,必须提醒的是ANSI C标准中的数据格式并不符合IEEE754标准,一些C语言编译器却遵循IEEE754(例如frinklin C51) .
常用C语言标准库函数
常用C语言标准库函数C语言编译系统提供了众多的预定义库函数和宏。
用户在编写程序时,可以直接调用这些库函数和宏。
这里选择了初学者常用的一些库函数,简单介绍了各函数的用法和所在的头文件。
1.测试函数Isalnum原型:int isalnum(int c)功能:测试参数c是否为字母或数字:是则返回非零;否则返回零头文件:ctype.hIsapha原型:int isapha(int c)功能:测试参数c是否为字母:是则返回非零;否则返回零头文件:ctype.hIsascii原型:int isascii(int c)功能:测试参数c是否为ASCII码(0x00~0x7F):是则返回非零;否则返回零头文件:ctype.hIscntrl原型:int iscntrl(int c)功能:测试参数c是否为控制字符(0x00~0x1F、0x7F):是则返回非零;否则返回零头文件:ctype.hIsdigit原型:int isdigit(int c)功能:测试参数c是否为数字:是则返回非零;否则返回零。
头文件:ctype.hIsgraph原型:int isgraph(int c)功能:测试参数c是否为可打印字符(0x21~0x7E):是则返回非零;否则返回零头文件:ctype.hIslower原型:int islower(int c)功能:测试参数c是否为小写字母:是则返回非零;否则返回零头文件:ctype.hIsprint原型:int isprint(int c)功能:测试参数c是否为可打印字符(含空格符0x20~0x7E):是则返回非零;否则返回零头文件:ctype.hIspunct原型:int ispunct(int c)功能:测试参数c是否为标点符号:是则返回非零;否则返回零头文件:ctype.hIsupper原型:int isupper(inr c)功能:测试参数c是否为大写字母:是则返回非零;否则返回零Isxdigit原型:int isxdigit(int c)功能:测试参数c是否为十六进制数:是则返回非零;否则返回零2.数学函数abs原型:int abs(int i)功能:返回整数型参数i的绝对值头文件:stdlib.h,math.hacos原型:double acos(double x)功能:返回双精度参数x的反余弦三角函数值头文件:math.hasin原型:double asin(double x)功能:返回双精度参数x的反正弦三角函数值头文件:math.hatan原型:double atan(double x)功能:返回双精度参数的反正切三角函数值头文件:math.hatan2原型:double atan2(double y,double x)功能:返回双精度参数y和x由式y/x所计算的反正切三角函数值头文件:math.hcabs原型:double cabs(struct complex znum)功能:返回一个双精度数,为计算出复数znum的绝对值。
(完整版)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语言中常用函数大全
(三)文件函数
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 结束
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C语言函数大全(h开头)
函数名: harderr
功能: 建立一个硬件错误处理程序
用法: void harderr(int (*fptr)());
程序例:
/*This program will trap disk errors and prompt
the user for action. Try running it with no
disk in drive A: to invoke its functions.*/
#include
#include
#include
#define IGNORE 0
#define RETRY 1
#define ABORT 2
int buf[500];
/*define the error messages for trapping disk problems*/ static char *err_msg[] = {
"write protect",
"unknown unit",
"drive not ready",
"unknown command",
"data error (CRC)",
"bad request",
"seek error",
"unknown media type",
"sector not found",
"printer out of paper",
"write fault",
"read fault",
"general failure",
"reserved",
"reserved",
"invalid disk change"
};
error_win(char *msg)
{
int retval;
cputs(msg);
/*prompt for user to press a key to abort, retry, ignore*/ while(1)
{
retval= getch();
if (retval == 'a' || retval == 'A')
{
retval = ABORT;
break;
}
if (retval == 'r' || retval == 'R')
{
retval = RETRY;
break;
}
if (retval == 'i' || retval == 'I')
{
retval = IGNORE;
break;
}
}
return(retval);
}
/*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;
}。