C语言函数大全(q,r开头)
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标准库) ............................................................... 错误!未定义书签。
1. <>:诊断............................................................................. 错误!未定义书签。
2. <>:字符类别测试 ............................................................ 错误!未定义书签。
3. <>:错误处理..................................................................... 错误!未定义书签。
4. <>:整型常量..................................................................... 错误!未定义书签。
5. <>:地域环境..................................................................... 错误!未定义书签。
6. <>:数学函数..................................................................... 错误!未定义书签。
7. <>:非局部跳转................................................................. 错误!未定义书签。
8. <>:信号............................................................................. 错误!未定义书签。
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语言常用数学函数

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

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

C语言图形编程一、字符屏幕一、屏幕操作函数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)。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 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;}。