C+语言函数库
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语言函数库-strstr

break;
else /*如果找到和s2第一个字符匹配的位置,开始逐个匹配s2后面的字符*/
for (sc1 = s1, sc2 = s2; sc1 !='\0'; ++sc1,++sc2)
{
const char *sc1, *sc2;
for (sc1 = s1, sc2 = s2; ; )
{
if (*++sc2 == '\0')
return ((char *)s1);
else if (*++sc1 != *sc2)
break;
C语言库函数用于在字符串中查找子串。函数原型为char *(strstr)(const char *s1, const char *s2)
函数的参数是两个字符串,函数返回s2在s1中第一次出现的位置。如果在s1中没有找到s2,返回空。
如果s2为空,则返回s1。
实现代码如下:
char* _strstr(const char *s1, const char *s2)
}
}
return (NULL) ;
}
它的实现比上一种简洁,但是调用了另一个库函数strchr。这个函数的作用是在字符串里查找字符,并返回第一次出现的位置。
本文来自CSDN huhao_bupt博客
{
if (*s2 == '\0') /*如果s2为空,则返回s1*/
return ((char *)s1);
C语言标准库

2.1.1 函数库简介
标准c语言包括语言标准和一组标准库 支持字符和字符串、输入与输出、数学函数、期与时 间转换、动态存储分配和其他特性 预处理器命令#include,引用这个库的头文件 例:
下列程序段中头文件math.h使程序能够访问余弦函数cos。 #include <math.h> double x,y; x = cos(y);
例 errno的常见用法是在调用库函数之前先清零,随后再进行检查:
errno=0; x = sqrt(y); if(errno) { printf(”?sqrt falled,code%d\n”,errno); x=0; }
2.3.4 erron.h
c语言实现通常定义一组标准错误码:
EDOM 参数不在数学函数能接受的域中。例如log函数的参数不能为负数参数
include命令包装连接声明
extern “C“ { #include”library.h“ }
2.3 主要的库文件
stddef.h math.h ctype.h erron.h stdbool.h iso645.h assert.h stdio.h stdlib.h string.h stdarg.h time.h setjmp.h signal.h
sqrt failed:domain error
2.3.5 bool、false、true 语法概要
#include <stdbool.h> #define #define #define #define bool _Bool /*无符号整数类型,只能保存数值0和1 */ false 0 true 1 __bool_true_false_are_define 1
C语言函数大全(q,r开头)

C语言函数大全(q,r开头)函数名: qsort功能: 使用快速排序例程进行排序用法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:#include#include#includeint sort_function( const void *a, const void *b);char list[5][4] = { "cat", "car", "cab", "cap", "can" };int main(void){int x;qsort((void *)list, 5, sizeof(list[0]), sort_function);for (x = 0; x < 5; x++)printf("%s\n", list[x]);return 0;}int sort_function( const void *a, const void *b){return( strcmp(a,b) );}函数名: qsort功能: 使用快速排序例程进行排序用法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:#include#includeint sort_function( const void *a, const void *b);char list[5][4] = { "cat", "car", "cab", "cap", "can" }; int main(void){int x;qsort((void *)list, 5, sizeof(list[0]), sort_function); for (x = 0; x < 5; x++)printf("%s\n", list[x]);return 0;}int sort_function( const void *a, const void *b){return( strcmp(a,b) );}函数名: raise功能: 向正在执行的程序发送一个信号用法: int raise(int sig);程序例:#includeint main(void){int a, b;a = 10;b = 0;if (b == 0)/* preempt divide by zero error */raise(SIGFPE);a = a / b;}函数名: rand功能: 随机数发生器用法: void rand(void);程序例:#include#includeint main(void){int i;printf("Ten random numbers from 0 to 99\n\n");for(i=0; iprintf("%d\n", rand() % 100);return 0;}函数名: randbrd功能: 随机块读用法: int randbrd(struct fcb *fcbptr, int reccnt); 程序例:#include#include#include#includeint main(void){char far *save_dta;char line[80], buffer[256];struct fcb blk;int i, result;/* get user input file name for dta */printf("Enter drive and file name (no path - i.e. a:file.dat)\n"); gets(line);/* put file name in fcb */if (!parsfnm(line, &blk, 1)){printf("Error in call to parsfnm\n");exit(1);}printf("Drive #%d File: %s\n\n", blk.fcb_drive, blk.fcb_name);/* open file with DOS FCB open file */bdosptr(0x0F, &blk, 0);/* save old dta, and set new one */save_dta = getdta();setdta(buffer);/* set up info for the new dta */blk.fcb_recsize = 128;blk.fcb_random = 0L;result = randbrd(&blk, 1);/* check results from randbrd */if (!result)printf("Read OK\n\n");else{perror("Error during read");exit(1);}/* read in data from the new dta */printf("The first 128 characters are:\n");for (i=0; iputchar(buffer[i]);/* restore previous dta */setdta(save_dta);return 0;}函数名: randbwr功能: 随机块写用法: int randbwr(struct fcp *fcbptr, int reccnt);程序例:#include#include#include#includeint main(void){char far *save_dta;char line[80];char buffer[256] = "RANDBWR test!";struct fcb blk;int result;/* get new file name from user */printf("Enter a file name to create (no path - ie. a:file.dat\n"); gets(line);/* parse the new file name to the dta */parsfnm(line,&blk,1);printf("Drive #%d File: %s\n", blk.fcb_drive, blk.fcb_name);/* request DOS services to create file */if (bdosptr(0x16, &blk, 0) == -1){perror("Error creating file");exit(1);}/* save old dta and set new dta */save_dta = getdta();setdta(buffer);/* write new records */blk.fcb_recsize = 256;blk.fcb_random = 0L;result = randbwr(&blk, 1);if (!result)printf("Write OK\n");else{perror("Disk error");exit(1);}/* request DOS services to close the file */ if (bdosptr(0x10, &blk, 0) == -1){perror("Error closing file");exit(1);}/* reset the old dta */setdta(save_dta);return 0;}函数名: random功能: 随机数发生器用法: int random(int num);程序例:#include#include#include/* prints a random number in the range 0 to 99 */int main(void){randomize();printf("Random number in the 0-99 range: %d\n", random (100)); return 0;}函数名: randomize功能: 初始化随机数发生器用法: void randomize(void);程序例:#include#include#includeint main(void){int i;randomize();printf("Ten random numbers from 0 to 99\n\n");for(i=0; iprintf("%d\n", rand() % 100);return 0;}函数名: read功能: 从文件中读用法: int read(int handle, void *buf, int nbyte);程序例:#include#include#include#include#include#includeint main(void){void *buf;int handle, bytes;buf = malloc(10);/*Looks for a file in the current directory named TEST.$$$ and attempts to read 10 bytes from it. To use this example you should create the file TEST.$$$*/if ((handle =open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1) {printf("Error Opening File\n");exit(1);}if ((bytes = read(handle, buf, 10)) == -1) {printf("Read Failed.\n");exit(1);else {printf("Read: %d bytes read.\n", bytes);}return 0;}函数名: realloc功能: 重新分配主存用法: void *realloc(void *ptr, unsigned newsize);程序例:#include#include#includeint main(void){char *str;/* allocate memory for string */str = malloc(10);/* copy "Hello" into string */strcpy(str, "Hello");printf("String is %s\n Address is %p\n", str, str);str = realloc(str, 20);printf("String is %s\n New address is %p\n", str, str); /* free memory */free(str);return 0;}函数名: rectangle功能: 画一个矩形用法: void far rectangle(int left, int top, int right, int bottom); 程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int left, top, right, bottom;/* 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 */}left = getmaxx() / 2 - 50;top = getmaxy() / 2 - 50;right = getmaxx() / 2 + 50;bottom = getmaxy() / 2 + 50;/* draw a rectangle */rectangle(left,top,right,bottom);/* clean up */getch();closegraph();return 0;}函数名: registerbgidriver功能: 登录已连接进来的图形驱动程序代码用法: int registerbgidriver(void(*driver)(void));程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;/* register a driver that was added into graphics.lib */ errorcode = registerbgidriver(EGAVGA_driver);/* report any registration errors */if (errorcode < 0){printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}/* draw a line */line(0, 0, getmaxx(), getmaxy());/* clean up */getch();closegraph();return 0;}函数名: remove功能: 删除一个文件用法: int remove(char *filename);程序例:#includeint main(void){char file[80];/* prompt for file name to delete */printf("File to delete: ");gets(file);/* delete the file */if (remove(file) == 0)printf("Removed %s.\n",file);elseperror("remove");return 0;}函数名: rename功能: 重命名文件用法: int rename(char *oldname, char *newname); 程序例:#includeint main(void){char oldname[80], newname[80];/* prompt for file to rename and new name */ printf("File to rename: ");gets(oldname);printf("New name: ");gets(newname);/* Rename the file */if (rename(oldname, newname) == 0)printf("Renamed %s to %s.\n", oldname, newname); elseperror("rename");return 0;}函数名: restorecrtmode功能: 将屏幕模式恢复为先前的imitgraph设置用法: void far restorecrtmode(void);程序例:#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int x, y;/* 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 */}x = getmaxx() / 2;y = getmaxy() / 2;/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT);outtextxy(x, y, "Press any key to exit graphics:");getch();/* restore system to text mode */restorecrtmode();printf("We're now in text mode.\n");printf("Press any key to return to graphics mode:");/* return to graphics mode */setgraphmode(getgraphmode());/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT);outtextxy(x, y, "We're back in graphics mode.");outtextxy(x, y+textheight("W"), "Press any key to halt:"); /* clean up */getch();closegraph();return 0;}。
C语言函数大全

C语言函数大全C语言是一种通用的高级语言,它广泛应用于系统软件、应用软件、驱动程序、网络通信、嵌入式系统等领域。
在C语言中,函数是非常重要的一部分,它可以帮助我们组织代码,提高代码的重用性和可维护性。
本文将介绍C语言中常用的函数,帮助大家更好地理解和应用C语言。
一、基本概念。
在C语言中,函数是一段完成特定任务的程序代码,它可以接受参数并返回值。
函数的基本结构包括函数名、参数列表、返回类型、函数体和返回语句。
函数的定义通常包括函数头和函数体两部分,函数头用于声明函数的名称、参数列表和返回类型,函数体包括具体的代码实现。
二、函数的声明与定义。
在C语言中,函数的声明和定义是分开的。
函数的声明用于告诉编译器函数的存在,函数的定义则包括函数的具体实现。
函数的声明通常包括函数名、参数列表和返回类型,函数的定义则包括函数名、参数列表、返回类型和函数体。
函数的声明和定义可以分开写在不同的文件中,通过头文件的方式进行引用。
三、函数的参数传递。
在C语言中,函数的参数传递可以通过值传递和引用传递两种方式。
值传递是指将实际参数的值复制一份传递给形式参数,函数内部对形式参数的修改不会影响实际参数。
引用传递是指将实际参数的地址传递给形式参数,函数内部对形式参数的修改会影响实际参数。
C语言中默认采用值传递的方式,如果需要使用引用传递,可以通过指针或引用的方式实现。
四、函数的返回值。
在C语言中,函数可以有返回值,也可以没有返回值。
有返回值的函数在定义时需要指定返回类型,函数体中需要使用return语句返回值。
没有返回值的函数通常使用void作为返回类型,函数体中可以省略return语句。
在调用函数时,可以通过赋值或者直接使用返回值的方式获取函数的返回结果。
五、常用的标准库函数。
C语言标准库提供了丰富的函数库,包括数学函数、字符串函数、输入输出函数等。
常用的标准库函数有printf、scanf、malloc、free、strcpy、strcat、strlen、sin、cos等。
C语言函数题库及答案

第六部分函数一、单项选择题1.C语言中的函数返回值的类型是由(D)决定A.return语句中的表达式B.调用函数的主调函数C.调用函数时临时D.定义函数时所指定的函数类型2.下面不正确的描述是(B)。
A.调用函数时,实参可以是表达式B.调用函数时,实参和形参可以共用内存单元C.调用函数时,将形参分配内存单元D.调用函数时,实参与形参的类型必须一致3.在C语言中,调用一个函数时,实参变量和形参变量之间的数据传递是(D)A.地址传递B.值传递C.由实参传递给形参,并由形参传回给实参D.由用户指定传递方式4.下面的函数调用语句中含有(A)个实参inta,b,c;intsum(intx1,intx2);……total=sum((a,b),c);A.2B.3C.4 D.55.在C语言中(C)A.函数的定义可以嵌套,但函数的调用不可以嵌套B.函数的定义和调用均不可以嵌套C.函数的定义不可以嵌套,但是函数的调用可以嵌套D.函数的定义和调用均可以嵌套6.关于C语言中的return语句正确的是(C)A.只能在主函数中出现B.在每个函数中都必须出现C.可以在一个函数中出现多次D.只能在除主函数之外的函数中出现7.两个形参中,第一个形参为指针类型、第二个形参为整型,则对函数形参的说明有错误的是(D)A.inta(floatx[],intn)B.inta(float*x,intn)C.inta(floatx[10],intn)D.inta(floatx,intn)8.在C语言中,函数的数据类型是指(A)A.函数返回值的数据类型B.函数形参的数据类型C.调用该函数时的实参的数据类型D.任意指定的数据类型9.已知如下定义的函数:fun1(a){printf("\n%d",a);}则该函数的数据类型是(C)A.与参数a的类型相同B.void型C.整型D.无法确定10.定义一个函数实现交换x和y的值,并将结果正确返回。
C语言库函数(R类字母)

perror("Error creating file");
exit(1);
}
/* save old dta and set new dta */
save_dta = getdta();
setdta(buffer);
#include <fcntl.h>
#include <process.h>
#include <sys\stat.h>
int main(void)
{
void *buf;
int handle, bytes;
buf = malloc(10);
struct fcb blk;
int i, result;
/* get user input file name for dta */
printf("Enter drive and file name (no path - i.e. a:file.dat)\n");
函数名: random
功 能: 随机数发生器
用 法: int random(int num);
程序例:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/* prints a random number in the range 0 to 99 */
函数名: raise
功 能: 向正在执行的程序发送一个信号
用 法: int raise(int sig);
程序例:
#include <signal.h>
(完整版)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() 函数, 可以根据自己的爱好把它放在程序的某个地方。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C语言参考手册之函数库介绍标准库的组成,及使用注意。
B.1 输入与输出:主要介绍流的概念等。
B.1.1 文件操作主要介绍 fopen()freopen() fflush()fclose()remove()rename()tmpfile()tmpnam()setvbuf(),setbuf()等。
B.1.2 格式化输出主要介绍 printf()fprintf()sprintf()vprintf()vfprintf()vsprintf()等。
B.1.3 格式化输入主要介绍 fscanf()scanf() sscanf()等。
B.1.4 字符输入/输出函数主要介绍 fgetc()fgets() fputc()fputs()getc()gets()putc()puts()putchar()ungetc()等。
B.1.5 直接输入输出主要介绍 fread()和fwrite()。
B.1.6 文件定位函数主要介绍 fseek()ftell()rewind()fgetpos()fsetpos()等。
B.1.7 错误处理函数主要介绍 clearerr()feof()ferror()perror()等。
B.2 字符类别测试:主要介绍isalnum(c)isalpha(c)iscntrl(c)isdigit(c)…tolower(c)toupper(c)等。
B.3 字符串函数:主要介绍 strcpy()strncpy() strcat()strncat()strcmp()strncmp()strchar()strrchr()strspn()strcspn()strpbrk()strstr()strlen()strerror()strtok()等。
B.4 数学函数:主要介绍sin()cos()tan()asin()acos()atan()atan2()sinh()cosh()ta nh()exp()log()log10()pow()sqrt()ceil()floor()fabs()ldexp()frexp ()modf()fmod()等。
B.5 实用函数:主要介绍 atof()atoi()atol()strtod()strtoul()rand()srand()calloc()malloc()realloc()free() abort()exit()atexit()system() getenv() bsearch() qsort()abs()labs()div()ldiv()等。
B.6 诊断:主要介绍 assert()。
B.7 可变参数表:主要介绍 va_listva_startva_end。
B.8 非局部跳转:主要介绍 setjmp()longjmp()等。
B.9 信号:主要介绍 signal()raise()等。
B.10 日期与时间函数:主要介绍 clock()time()difftime()mktime()asctime()ctime()strftime()等。
B.11 与具体实现相关的限制:和主要介绍整型大小的常量,浮点运算的一些常量。
换页C语言参考手册之函数库 Ver:1.0 Date:2005-8-19LW7807@制作摘录自《C程序设计语言(第二版)》K&R著徐宝文等译版权属原作者和出版社所有- 2 / 15-附录B:标准库返回目录本附录总结了ANSI标准定义的函数库。
标准库不是C语言本身的构成部分,但是支持标准C的实现会提供该函数库中的函数声明、类型及宏定义。
在这部分内容中,我们省略了一些使用比较受限的函数以及一些可以通过其他函数简单合成的函数,也省略了多字节字符的内容,同时,也不准备讨论与区域相关的一些属性,也就是与本地语言、国籍或文化相关的属性。
标准库中的函数、类型以及宏分别在下面的标准头文件中定义:可以通过下列方式访问头文件:#include头文件的包含顺序是任意的,并可包含任意多次。
头文件必须被包含在任何外部声明或定义之外,并且,必须在使用头文件中的任何声明之前包含头文件。
头文件不一定是一个源文件。
以下划线开头的外部标识符保留给标准库使用,同时,其他所有以一个下划线和一个大写字母开头的标识符以及两个下划线开头的标识符也都保留给标准库使用。
B.1 输入输出:返回目录头文件中定义的输入和输出函数、类型以及宏的数目几乎占整个标准库的三分之一。
流(stream)是与磁盘或其他外围设备关联的数据的源或目的地。
尽管在某些系统中(如著名的UNIX系统中),文本流和二进制流是相同的,但标准库仍然提供了这两种类型的流。
文本流是由文本行组成的序列,每行包含0个或多个字符,并以‘\n’结尾。
在某些环境中,可能需要将文本流转换为其他表示形式(例如把‘\n’映射成回车符和换行符),或从其他表示形式转换为文本流。
二进制流是由未经处理的字节构成的序列,这些字节记录着内部数据,并具有下列性质:如果在同一系统中写入二进制流,然后再读取该二进制流,则读出和写入的内容完全相同。
打开一个流,将把流与一个文件或设备连接起来,关闭流将断开这种连接。
打开一个文件将返回一个指向FILE类型对象的指针,该指针记录了控制该流的所有必要信息。
在不引起歧义的情况下,我们在下文中将不再区分“文件指针”和“流”。
程序开始执行是,stdin、stdout和stderr这3个流已经处于打开状态。
B.1.1 文件操作返回目录下列函数用于处理与文件有关的操作。
其中,类型size_t是由运算符sizeof生成的无符号整形。
FILE *fopen(const char *filenameconst char *mode)fopen函数打开filename指定的文件,并返回一个与之相关联的流。
如果打开失败,则返回NULL。
访问模式mode可以为下列合法值之一:“r”打开文本文件用于读“w”创建文本文件用于写,并删除已存在的内容(如果有的话)“a”追加;打开或创建文本文件,并向文件末尾追加内容“r+”打开文本文件用于更新(即读和写)“w+”创建文本文件用于更新,并删除已存在的内容(如果有的话)“a+”追加;打开或创建文本文件用于更新,写文件时追加到文件末尾后三种方式(更新方式)允许对同一个文件进行读和写。
在读和写的交叉过程中,必须调用fflush函数或文件定位函数。
如果在上述访问模式之后再加上b如“rb”或“w+b”等,则表示对二进制文件进行操作。
文件名filname限定最多为FILENAME_MAX个字符。
一次最多可打开FOPEN_MAX个文件。
FILE *freopen(const char *filenameconst char *modeFILE *stream)freopen函数以mode指定的模式打开filename指定的文件,并将该文件关联到stream指定的流。
它返回stream;若出错则返回NULL。
freopen函数一般用于改变与stdin、stdout和stderr相关联的文件。
换页C语言参考手册之函数库 Ver:1.0 Date:2005-8-19LW7807@制作摘录自《C程序设计语言(第二版)》K&R著徐宝文等译版权属原作者和出版社所有- 3 / 15-int fflush(FILE *stream)对输出流来说,fflush函数将已写到缓冲区但尚未写入文件的所有数据写到文件中。
对输入流来说,其结果是未定义的。
如果在写的过程中发生错误,则返回EOF,否则返回0。
fflush(NULL)将清洗所有的输出流。
int fclose(FILE *stream)fclose函数将所有未写入的数据写入stream中,丢弃缓冲区中的所有未读输入数据,并释放自动分配的全部缓冲区,最后关闭流。
若出错则返回EOF,否则返回0。
int remove(const char *filename) 返回目录remove函数删除filename指定的文件,这样,后续试图打开该文件的操作将失败。
如果删除操作失败,则返回一个非0值。
int rename(const char *oldnameconst char *newname)rename函数修改文件的名字。
如果操作失败,则返回一个非0值。
FILE *tmpfile(void)tmpfile函数以模式“w+b”创建一个临时文件,该文件在被关闭或程序正常结束时将被自动删除。
如果创建操作成功,该函数返回一个流;如果创建文件失败,则返回NULL。
char *tmpnam(char s[L_tmpnam]) 返回目录tmpnam(NULL)函数创建一个与现有文件名不同的字符串,并返回一个指向一内部静态数组的指针。
tmpname(s)函数把创建的字符串保存到数组s中,并将它作为函数值返回。
s中至少要有L_tmpnam个字符的空间。
tmpnam函数在每次被调用时均生成不同的名字。
在程序执行的过程中,最多只能确保生成TMP_MAX个不同的名字。
注意,tmpnam函数只能用于创建一个名字,而不能创建一个文件。
int setvbuf(FILE *streamchar *bufint modesize_t size)setvbuf函数控制流stream的缓冲。
在执行读、写以及其他任何操作之前必须调用此函数。
当mode的值为_IOFBF时,将进行完全缓冲。
当mode的值为_IOLBF时,将对文本文件进行行缓冲,当mode的值为_IONBF时,表示不设置缓冲。
如果buf的值不是NULL,则setvbuf函数将buf 指向的区域作为流的缓冲区,否则将分配一个缓冲区。
size决定缓冲区的长度。
如果setvbuf函数出错,则返回一个非0值。
void setbuf(FILE *streamchar *buf)如果buf的值为NULL,则关闭流stream的缓冲;否则setbuf函数等价于(void)setvbuf(streambuf_IOFBFBUFSIZ)。
B.1.2 格式化输出返回目录printf函数提供格式化输出转换。
int fprintf(FILE *streamconst char *format…)fprintf函数按照format说明的格式对输出进行转换,并写到stream流中。
返回值是实际写入的字符数。
若出错则返回一个负值。
格式串由两种类型的对象组成:普通字符(将被复制到输出流中)与转换说明(分别决定下一后续参数的转换和打印)。
每个转换说明均以字符%开头,以转换字符结束。
在%与转换字符之间可以依次包含下列内容:◆标志(可以以任意顺序出现),用于修改转换说明- 指定被转换的参数在其字段内左对齐+ 指定在输出的数前面加上正负号空格如果第一个字符不是正负号,则在其前面加上空格0 对于数值转换,当输出长度小于字段宽度时,添加前导0进行填充# 指定另一种输出形式。