C语言函数大全(q,r开头)

合集下载

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语言函数库详解(收藏版)

C语言函数库详解(收藏版)

c语言函数库目录第一章(C标准库) ............................................................... 错误!未定义书签。

1. <>:诊断............................................................................. 错误!未定义书签。

2. <>:字符类别测试 ............................................................ 错误!未定义书签。

3. <>:错误处理..................................................................... 错误!未定义书签。

4. <>:整型常量..................................................................... 错误!未定义书签。

5. <>:地域环境..................................................................... 错误!未定义书签。

6. <>:数学函数..................................................................... 错误!未定义书签。

7. <>:非局部跳转................................................................. 错误!未定义书签。

8. <>:信号............................................................................. 错误!未定义书签。

c语言常用的数学函数

c语言常用的数学函数

以下是一些常见的C语言数学函数:1.数值计算函数:●abs():返回一个整数的绝对值。

●fabs():返回一个浮点数的绝对值。

●sqrt():计算一个数的平方根。

●pow():计算一个数的指定次幂。

●exp():计算自然对数的指数。

●log():计算一个数的自然对数。

●log10():计算一个数的以10为底的对数。

●ceil():向上取整,返回不小于给定参数的最小整数。

●floor():向下取整,返回不大于给定参数的最大整数。

●round():四舍五入,返回距离给定参数最近的整数。

2.三角函数:●sin():计算给定角度的正弦值。

●cos():计算给定角度的余弦值。

●tan():计算给定角度的正切值。

●asin():计算给定值的反正弦。

●acos():计算给定值的反余弦。

●atan():计算给定值的反正切。

●atan2():计算给定两个参数的反正切。

3.随机数生成函数:●rand():生成一个范围在0到RAND_MAX之间的随机整数。

●srand():设置随机数生成器的种子值。

4.其他函数:●min():返回两个给定值中较小的那个。

●max():返回两个给定值中较大的那个。

●fmod():计算给定两个浮点数的余数。

这仅仅是一些常见的C语言数学函数,math.h库中还有更多可用的函数。

在使用这些函数之前,请确保正确包含了<math.h>头文件,并根据需要使用适当的参数和类型进行函数调用。

可以参考C语言的相关文档以获取更详细的信息。

C语言常用数学函数

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语言库函数使用大全

C语言库函数使用大全C语言是一种面向过程的编程语言,它提供了大量的库函数来方便开发者进行各种操作。

在本篇文章中,我将介绍一些常用的C语言库函数,并说明它们的使用方法。

1.字符串处理函数:- strlen:用于计算字符串的长度。

- strcat:用于将两个字符串连接起来。

- strcpy:用于将一个字符串复制到另一个字符串中。

- strcmp:用于比较两个字符串是否相等。

2.数学函数:- abs:返回一个整数的绝对值。

- sqrt:返回一个数的平方根。

- pow:计算一个数的指定次幂。

- rand:生成一个随机数。

3.输入输出函数:- printf:用于打印输出。

- scanf:用于接受用户的输入。

- getchar:用于从输入流中读取一个字符。

- putchar:用于将一个字符输出到屏幕上。

4.内存管理函数:- malloc:用于在堆中分配指定大小的内存块。

- free:用于释放之前分配的内存。

- calloc:可以在堆中分配指定数量和大小的内存,并将每个字节初始化为0。

- realloc:用于调整之前分配的内存块的大小。

5.时间日期函数:6.文件操作函数:- fopen:用于打开一个文件。

- fclose:用于关闭一个文件。

- fgets:从文件中读取一行字符串。

- fputs:向文件中写入一行字符串。

7.数组处理函数:- memset:将一个数组的所有元素设置为指定的值。

- memcpy:将一个数组的内容复制到另一个数组中。

- memmove:将一个数组的内容移动到另一个数组中,处理重叠情况。

- qsort:用于对数组进行快速排序。

这只是C语言库函数的一小部分,还有很多其他函数可供使用。

在实际开发中,根据需求选择适合的函数,可以提高代码的效率和可读性。

总结:C语言库函数提供了丰富的功能,可以帮助开发者简化编程过程。

在使用库函数时,需要仔细阅读函数的说明文档,并根据需求选择适合的函数和参数。

通过充分利用库函数,可以提高代码的开发效率和质量。

c语言常用函数大全及详解

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语言中,函数是一种模块化编程的基本方法,通过函数可以将一段代码进行封装和复用,提高了代码的可读性和可维护性。

本文将介绍一些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语言图形编程一、字符屏幕一、屏幕操作函数1. clrscr()清除字符窗口函数2. window()字符窗口函数3. gotoxy()光标定位函数4. clreol() 清除光标行尾字符函数5. insline() 插入空行函数6. delline() 删除一行函数7. gettext() 拷进文字函数8. puttext() 拷出文字函数9. movetext() 移动文字函数二、字符属性函数10. textmode() 文本模式函数11. highvideo()高亮度函数12. lowvideo() 低亮度函数13. normvideo(void);14. textcolor() 文本颜色函数15. textattr() 文本属性函数16.textbackground() 文本背景函数三、屏显状态函数17. wherex() 光标处x坐标函数18. wherey() 光标处y坐标函数19. gettextinfo() 获取文本窗口信息函数在Borland C++里面提供了字符屏幕和图形函数。

字符屏幕的核心是窗口(Window),它是屏幕的活动部分,字符输出或显示在活动窗口中进行。

窗口在缺省时,就是整个屏幕。

窗口可以根据需要指定其大小。

同样,对图形函数的操作,也提供了(Viewport)。

也就是说图形函数的操作都是在视口上进行。

图形视口与字符窗口具有相同的特性,用户可以在屏幕上定义大小不同的视口,若不定义视口大小,它就是整个屏幕。

窗口是在字符屏幕下的概念,只有字符才能在窗口中显示出来,这时用户可以访问的最小单位为一个字符。

视口是在图形屏幕状态下的概念,文本与图形都可以在视口上显示,用户可访问的最小单位是一个像素(像素这一术语最初用来指显示器上最小的、单独的发光点单元。

然而现在,其含义拓宽为指图形显示器上的最小可访问点)。

字符和图形状态下,屏幕上的位置都是由它们的行与列所决定的。

有一点须指出:字符状态左上角坐标为(1,1),但图形左上角坐标为(0,0)。

C语言中的数学函数

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的对数值。

C语言文件操作函数大全

C语言文件操作函数大全

C语言文件操作函数大全1. `fopen`:打开文件```FILE* fopen(const char* filename, const char* mode);```该函数用于打开一个文件,成功打开返回文件指针,打开失败返回`NULL`。

`filename` 是要打开的文件名,`mode` 是打开模式,常用的模式有 "r"(只读)、"w"(可写,若文件不存在则创建新文件)、"a"(追加模式)。

2. `fclose`:关闭文件```int fclose(FILE* stream);```该函数用于关闭一个文件,成功关闭返回0,关闭失败返回 `EOF`。

`stream` 是要关闭的文件指针。

3. `fread`:读取文件内容```size_t fread(void* ptr, size_t size, size_t count, FILE* stream);```该函数从文件中读取内容,存储到指定的内存块。

`ptr` 是指向要读取数据的内存块的指针,`size` 是每个数据项的大小,`count` 是要读取的数据项数目。

4. `fwrite`:写入文件内容```size_t fwrite(const void* ptr, size_t size, size_t count, FILE* stream);```该函数将指定的内存块内容写入文件。

`ptr` 是指向要写入数据的内存块的指针,`size` 是每个数据项的大小,`count` 是要写入的数据项数目。

5. `fgetc`:读取一个字符```int fgetc(FILE* stream);```该函数从文件中读取一个字符,成功读取返回字符对应的整数值,读取失败或到达文件末尾返回`EOF`。

6. `fputc`:写入一个字符```int fputc(int c, FILE* stream);```该函数将一个字符写入文件,成功写入返回写入的字符,写入失败返回`EOF`。

(完整版)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语言数学函数大全及详解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语言中常用函数大全

C语言中常用函数大全
注意: 这里原始内‎存中 的数据‎还是保 持不‎变的。当 内存不再‎使用时 ,应使用 fr ‎ee()函数将内存‎块释放。
(三)文件函数
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) Filen‎ame:是字符串,表示打开的‎文件名,文件名前可 ‎ 以带路径。 Mode:也是字符串‎,表示打开文‎ 件的方式。 功能----按指定方式‎ 打开文件。 返回值----如果文件打‎开成功,返回“文件结构体 ‎ 指针”,否者返回 N‎ ULL(如:文件不存在 ‎ 或则 写文件‎时不能创建‎ )。 Fopen‎(“A:\\user\\asd.txt”,”r+”); 2:关闭文件 Int*fclos‎ e(FILE*filen‎ ame) 正常关闭返‎ 回0;否者返回 非 0。
With:指定输入数‎ 据的宽度,遇空格、Tab、\n 结束

C语言中常用函数大全

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语言中必不可少的函数

c语言中必不可少的函数在C语言中,有一些函数被认为是必不可少的,它们是开发者们在日常编程中经常使用的基本函数。

这些函数包括库函数、系统函数和用户自定义函数。

下面将介绍一些C语言中必不可少的函数。

1. printf(函数:这是C语言中最常用的输出函数,它用于按指定格式将数据输出到标准输出设备(通常是屏幕)上。

2. scanf(函数:与printf(函数相对应的是scanf(函数,它用于从标准输入设备(通常是键盘)获取用户输入的数据,并按指定格式存储到变量中。

3. malloc(函数:它是C语言中的动态内存分配函数。

通过malloc(函数可以在程序运行时动态地分配指定大小的内存空间,并返回一个指向该空间的指针。

4. free(函数:与malloc(函数对应的是free(函数,它用于释放通过malloc(函数分配的动态内存空间,在不再需要使用该空间时必须调用该函数。

5. strcpy(函数:它用于将一个字符串(包括字符串的结束标志'\0')复制到另一个字符串中。

6. strlen(函数:它用于获取一个字符串的长度,即该字符串的字符数(不包括结束标志'\0')。

7. strcmp(函数:它用于比较两个字符串的大小关系,若两个字符串相等则返回0,若第一个字符串大于第二个字符串则返回正数,若第一个字符串小于第二个字符串则返回负数。

8. fopen(函数:它用于打开一个文件,并返回一个指向该文件的指针,以供后续的读写操作。

9. fclose(函数:与fopen(函数对应的是fclose(函数,用于关闭一个已打开的文件。

10. fseek(函数:它用于在文件中移动文件指针的位置,从而定位文件中的某个位置进行读写操作。

11. int main(函数:在C语言程序中,必须定义一个名为main(的函数作为程序的入口点,程序的执行从main(函数开始。

除了上述库函数和系统函数外,C语言还允许开发者定义自己的函数。

c语言的常用函数

c语言的常用函数

c语言的常用函数c语言是一门流行的多用途的编程语言,几乎在所有的领域都有应用。

在把它应用到实际项目中时,需要熟悉c语言常用函数。

本文介绍c语言中105个常用函数,包括数据类型转换、输入输出等函数,以及字符串处理、文件处理、学习内存管理、数学函数、定时器等函数,可以帮助程序员们更加熟悉c语言中的常用函数,从而更好地实现编程项目。

一、数据类型转换函数1、atoi()一个字符串转换成一个整数。

2、atof()一个字符串转换成浮点数。

3、atol()一个字符串转换成长整数。

4、strtod()一个字符串转换成双精度浮点数。

5、strtol()一个字符串转换成长整数。

6、strtoul()字符串转换成无符号长整数。

7、itoa()整数转换为字符串。

8、ftoa()浮点数转换为字符串。

9、ltoa()长整数转换为字符串。

二、输入输出函数1、printf()格式化的数据输出到标准输出设备。

2、scanf() 从标准输入设备读取格式化的数据。

3、fprintf()格式化的数据写入指定的文件。

4、fscanf() 从指定的文件读取格式化的数据。

5、sprintf()格式化的数据存储到字符串变量中。

6、sscanf() 从字符串变量中读取格式化的数据。

三、字符串处理函数1、strlen()算字符串长度。

2、strcpy() 从源字符串复制到目标字符串。

3、strcat()源字符串添加到目标字符串的末尾。

4、strcmp()较两个字符串。

5、strncpy() 从源字符串复制到目标字符串,长度不超过指定的长度。

6、strncat()源字符串添加到目标字符串的末尾,长度不超过指定的长度。

7、strncmp()较两个字符串,长度不超过指定的长度。

8、strstr()到第一个字符串中出现第二个字符串的位置。

9、strchr()到第一个字符串中出现字符c的位置。

10、strrchr()到第一个字符串中最后一次出现字符c的位置。

c语言常用函数

c语言常用函数

‎b‎c mp(比‎较内存内容‎)相‎关函数‎b cmp,‎s trca‎s ecmp‎,strc‎m p,st‎r coll‎,strn‎c mp,s‎t rnca‎s ecmp‎表头‎文件 #‎i nclu‎d e<st‎r ing.‎h>‎定义函数‎int ‎b cmp ‎( con‎s t vo‎i d *s‎1,con‎s t vo‎i d * ‎s2,in‎t n);‎函数‎说明 b‎c mp()‎用来比较s‎1和s2所‎指的内存区‎间前n个字‎节,若参数‎n为0,则‎返回0。

‎返回值‎若参数‎s1 和s‎2所指的‎内存内容都‎完全相同则‎返回0 值‎,否则返回‎非零值。

‎附加说‎明建议‎使用mem‎c mp()‎取代。

‎范例‎参考mem‎c mp()‎。

‎‎bc‎o py(拷‎贝内存内容‎)相‎关函数‎m emcc‎p y,me‎m cpy,‎m emmo‎v e,st‎r cpy,‎c trnc‎p y‎表头文件‎#inc‎l ude ‎<stri‎n g.h>‎定义‎函数 v‎o id b‎c opy ‎( con‎s t vo‎i d *s‎r c,vo‎i d *d‎e st ,‎i nt n‎);‎函数说明‎bcop‎y()与m‎e mcpy‎()一样都‎是用来拷贝‎s rc所指‎的内存内容‎前n个字节‎到dest‎所指的地址‎,不过参数‎s rc与d‎e st在传‎给函数时是‎相反的位置‎。

返‎回值‎附加说‎明建议‎使用mem‎c py()‎取代‎范例 #‎i nclu‎d e<st‎r ing.‎h>ma‎i n()‎{cha‎r des‎t[30]‎=”str‎i ng(a‎)”;c‎h ar s‎r c[30‎]=”st‎r ing\‎0stri‎n g”;‎i nt i‎;bco‎p y(sr‎c,des‎t,30)‎;/* s‎r c指针放‎在前*/‎p rint‎f(bco‎p y():‎“)f‎o r(i=‎0;i<3‎0;i++‎)pri‎n tf(“‎%c”,d‎e st[i‎]);m‎e mcpy‎(dest‎src,‎30); ‎/*des‎t指针放在‎钱*/p‎r intf‎(…\nm‎e mcpy‎() : ‎“);f‎o r(i=‎0;i<3‎0;i++‎)pri‎n tf(“‎%c”,d‎e st[i‎]);‎执行‎b copy‎() : ‎s trin‎g str‎i ngm‎e mcpy‎() :s‎t ring‎srin‎g‎‎bz‎e ro(将‎一段内存内‎容全清为零‎)相‎关函数‎m emse‎t,swa‎b表‎头文件‎#incl‎u de<s‎t ring‎.h>‎定义函数‎ voi‎d bze‎r o(vo‎i d *s‎,int ‎n);‎函数说明‎ bze‎r o()会‎将参数s所‎指的内存区‎域前n个字‎节,全部设‎为零值。

c语言标准库中的函数名

c语言标准库中的函数名

c语言标准库中的函数名
C语言标准库中的函数名
C语言标准库是C语言程序设计中不可或缺的一部分,它包含了大量的函数,可以用于各种不同的操作。

以下是C语言标准库中常用的函数名:
1. 字符串处理函数
- strcpy:将一个字符串复制到另一个字符串中
- strcat:将一个字符串连接到另一个字符串的末尾
- strlen:计算一个字符串的长度
- strcmp:比较两个字符串是否相等
- strchr:在一个字符串中查找某个字符第一次出现的位置
2. 数学函数
- abs:返回一个整数的绝对值
- sqrt:返回一个浮点数的平方根
- pow:求幂运算
- sin/cos/tan:三角函数
3. 文件操作函数
- fopen/fclose:打开/关闭文件
- fread/fwrite:读取/写入文件数据
- fseek/ftell:移动文件指针/获取当前指针位置
4. 内存操作函数
- malloc/free:动态分配/释放内存空间
- memset/memcpy:设置/复制内存内容
5. 时间日期函数
- time:获取当前时间戳
- localtime/gmtime:将时间戳转换为本地时间/协调世界时(UTC)时间格式
- strftime:格式化输出时间日期信息
以上是C语言标准库中常用的一些函数名,当然还有很多其他的函数,需要根据具体需求选择使用。

在编写C语言程序时,熟练掌握这些函
数的用法可以提高编程效率和代码质量。

C语言文件操作函数大全(超详细)

C语言文件操作函数大全(超详细)

C语⾔⽂件操作函数⼤全(超详细)相关函数 open,fclose表头⽂件 #include<stdio.h>定义函数 FILE * fopen(const char * path,const char * mode);函数说明参数path字符串包含欲打开的⽂件路径及⽂件名,参数mode字符串则代表着流形态。

r 打开只读⽂件,该⽂件必须存在。

r+ 打开可读写的⽂件,该⽂件必须存在。

w 打开只写⽂件,若⽂件存在则⽂件长度清为0,即该⽂件内容会消失。

若⽂件不存在则建⽴该⽂件。

w+ 打开可读写⽂件,若⽂件存在则⽂件长度清为零,即该⽂件内容会消失。

若⽂件不存在则建⽴该⽂件。

a 以附加的⽅式打开只写⽂件。

若⽂件不存在,则会建⽴该⽂件,如果⽂件存在,写⼊的数据会被加到⽂件尾,即⽂件原先的内容会被保留。

a+ 以附加⽅式打开可读写的⽂件。

若⽂件不存在,则会建⽴该⽂件,如果⽂件存在,写⼊的数据会被加到⽂件尾后,即⽂件原先的内容会被保留。

复制代码代码如下:r Open text file for reading. The stream is positioned at the beginning of the file.r+ Open for reading and writing. The stream is positioned at the beginning of the file.w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is posi‐tioned at the beginning of the file.a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at theend of the file.a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file posi‐tion for reading is at the beginning of the file, but output is always appended to the end of the file.上述的形态字符串都可以再加⼀个b字符,如rb、w+b或ab+等组合,加⼊b 字符⽤来告诉函数库打开的⽂件为⼆进制⽂件,⽽⾮纯⽂字⽂件。

C语言标准库函数大全

C语言标准库函数大全
file://F:\DOCUME~1\lichao\LOCALS~1\Te 2 of 22
相册
BOOK photo 自己做的
Expert
anjou jeffreyzhao Ricktroy shenfx 吕震宇 随心所欲 小寒
Friends
Hack Site
Hack a day Hack And Slash Hack Canada
2009-4-3
目录函数,所在函数库为dir.h、dos.h int chdir(char *path) 使指定的目录path(如:"C:\\WPS")变成当前的工 作目录,成功返回0 int findfirst(char *pathname,struct ffblk *ffblk,int attrib) 查找指定的文件,成功返回0 pathname为指定的目录名和文件名,如"C:\\WPS\\TXT" ffblk为指定的保存文件信息的一个结构,定义如下: ┏━━━━━━━━━━━━━━━━━━┓ ┃struct ffblk ┃ ┃{ ┃ ┃ char ff_reserved[21]; /*DOS保留字*/┃ ┃ char ff_attrib; /*文件属性*/ ┃ ┃ int ff_ftime; /*文件时间*/ ┃ ┃ int ff_fdate; /*文件日期*/ ┃ ┃ long ff_fsize; /*文件长度*/ ┃ ┃ char ff_name[13]; /*文件名*/ ┃ ┃} ┃ ┗━━━━━━━━━━━━━━━━━━┛ attrib为文件属性,由以下字符代表 ┏━━━━━━━━━┳━━━━━━━━┓ ┃FA_RDONLY 只读文件┃FA_LABEL 卷标号┃ ┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃ ┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃ ┗━━━━━━━━━┻━━━━━━━━┛ 例: struct ffblk ff; findfirst("*.wps",&ff,FA_RDONLY);
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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;}。

相关文档
最新文档