《C/C++函数与算法》
《C/C++函数与算法》 |
| 版本 | 作者 | 参与者 | 完成日期 | 备注 |
| YanlzCC++_Algorithm_V01_1.0 | 严立钻 |
| 2020.01.17 |
|
|
|
|
|
|
|
##《C/C++函数与算法》发布说明:
++++“C/C++函数与算法”:是对“C++C铸就生存利器”的综合探索;C/C++作为万能语言,可以开发嵌入式、物联网,也可以开发游戏(Cocos2dx、UE4);
++++“C/C++函数与算法”:定位在一个科普类知识,了解C/C++相关库和算法!
@@提示:有些博客可能只是开了头,如果感兴趣的同学,可以“点赞”或“评论区留言”,只要关注的同学多了,那就会继续完善哟!(“++==”,表示没有写完的,如果关注度不高就不完善了;“++ok++”,表示此篇博客已经完成,是阶段性完整的!)
++++姊妹篇:
++++【C/C++函数与算法(C++库独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104062275
++++【C/C++函数与算法(算法独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104062527
++++【C/C++函数与算法(Linux C独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104076473
++++【C++C铸就生存利器】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥优快云空间】:https://blog.youkuaiyun.com/VRunSoftYanlz/

++++VR云游戏=Unity+SteamVR+云技术+5G+AI;(说明:AI人工智能不是我们的主要研究技术,只是了解一下,领略一下有风的感觉!但是,VR是我们的研究重点)
$$$$博客溯源:



##《C/C++函数与算法》目录
#第一篇:C语言函数
#第二篇:C++输入/输出
#第三篇:标准容器
#第四篇:算法
#第五篇:立钻哥哥带您C/C++编程

#第一篇:C语言函数
#第一篇:C语言函数 |
#第一篇:C语言函数
++++立钻哥哥:C语言和C++语言的类库丰富,利用这些函数可以实现各种功能,这就需要我们掌握C和C++最为常用的函数;在第四篇还会介绍常用的算法,算法是程序员设计的灵魂;
++++A1、ctype.h
++++A2、stdio.h
++++A3、string.h
++++A4、stdlib.h
++++A5、math.h
++++A6、conio.h
++++A7、graphics.h
++++A8、stdarg.h
++++A9、time.h
++++A10、dir.h
++++A11、立钻哥哥带您了解其他C函数库
++A1、ctype.h
++A1、ctype.h |
++A1、ctype.h(字符操作函数)
++++立钻哥哥:ctype.h包含C语言中的字符测试函数、字符转换函数;ctype.h库函数在C++中调用:#include <cctype>
#注意:C++标准库也同样包含C标准库,使用时在库名前加c,例如,C标准库中的ctype.h在C++中则变为cctype; |
++++A1.1、字符测试函数
++++A1.2、字符转换函数
++A1.1、字符测试函数
++A1.1、字符测试函数 |
++A1.1、字符测试函数
++++立钻哥哥:C语言中的字符测试函数可以判断字符属于何种类型:数字字符、英文字母、空白字符、小写英文字母、大写英文字母、可打印字符、ASCII码的范围等;
++++A1.1.1、isalnum
++++A1.1.2、isalpha
++++A1.1.3、isascii
++++A1.1.4、iscntrl
++++A1.1.5、isdigit
++++A1.1.6、isgraph
++++A1.1.7、islower
++++A1.1.8、isprint
++++A1.1.9、ispunct
++++A1.1.10、isspace
++++A1.1.11、isxdigit
++++A1.1.1、isalnum
++++A1.1.1、isalnum |
++A1.1.1、isalnum
++++立钻哥哥:isalnum函数是判断字符是否是英文字母或数字字符;
int isalnum(int ch); |
++++A1.1.2、isalpha
++++A1.1.2、isalpha |
++A1.1.2、isalpha
++++立钻哥哥:函数isalpha的作用是判断ch是否是英文字母;
int isalpha(int ch); |
++++A1.1.3、isascii
++++A1.1.3、isascii |
++A1.1.3、isascii
++++立钻哥哥:函数isascii的作用是判断ch的ASCII码是否位于0~127之间;
int isascii(int ch); |
++++A1.1.4、iscntrl
++++A1.1.4、iscntrl |
++A1.1.4、iscntrl
++++立钻哥哥:函数iscntrl的作用是判断ch是否是控制字符,即ASCII码是否位于0~31之间或等于0x7f(Delete键的ASCII码);
int iscntrl(int ch); |
++++A1.1.5、isdigit
++++A1.1.5、isdigit |
++A1.1.5、isdigit
++++立钻哥哥:函数isdigit的作用是判断ch是否是数字字符,即是否是’0’~’9’之间的字符;
int isdigit(int ch); |
++++A1.1.6、isgraph
++++A1.1.6、isgraph |
++A1.1.6、isgraph
++++立钻哥哥:函数isgraph的作用是判断ch是否是除了空格外的可打印字符;
int isgraph(int ch); |
++++A1.1.7、islower
++++A1.1.7、islower |
++A1.1.7、islower
++++立钻哥哥:函数islower的作用是判断ch是否是小写英文字母;
int islower(int ch); |
++++A1.1.8、isprint
++++A1.1.8、isprint |
++A1.1.8、isprint
++++立钻哥哥:函数isprint的作用是判断ch是否是可打印字符(包括空格符);
int isprint(int ch); |
++++A1.1.9、ispunct
++++A1.1.9、ispunct |
++A1.1.9、ispunct
++++立钻哥哥:函数ispunct的作用是判断ch是否是标点符号;
int ispunct(int ch); |
++++A1.1.10、isspace
++++A1.1.10、isspace |
++A1.1.10、isspace
++++立钻哥哥:函数isspace的作用是判断ch是否是空白符,空白符包括空格符、水平制表符、回车符等;
int isspace(int ch); |
++++A1.1.11、isxdigit
++++A1.1.11、isxdigit |
++A1.1.11、isxdigit
++++立钻哥哥:函数isxdigit的作用是判断ch是否是十六进制数字0~9和A~F(a~f)对应的字符;
int isxdigit(int ch); |
++A1.2、字符转换函数
++A1.2、字符转换函数 |
++A1.2、字符转换函数
++++立钻哥哥:字符转换函数包括3个:将大写英文字母转换为小写英文字母、将小写英文字母转换为大写英文字母、将字符转换为ASCII码;
++++A1.2.1、tolower
++++A1.2.2、toupper
++++A1.2.3、toascii
++++A1.2.1、tolower
++++A1.2.1、tolower |
++A1.2.1、tolower
++++立钻哥哥:如果ch是’A’~’Z’之间的大写英文字母,函数tolower会将ch转换为’a’~’z’之间的小写英文字母;
int tolower(int ch); |
++++A1.2.2、toupper
++++A1.2.2、toupper |
++A1.2.2、toupper
++++立钻哥哥:函数toupper的作用是将小写英文字母’a’~’z’转换为大写英文字母’A’~’Z’;
int toupper(int ch); |
++++A1.2.3、toascii
++++A1.2.3、toascii |
++A1.2.3、toascii
++++立钻哥哥:函数toascii的作用是将字符转换为相应的ASCII码;
int toascii(int ch); |
++A2、stdio.h
++A2、stdio.h |
++A2、stdio.h
++++立钻哥哥:头文件stdio.h包含C语言的标准输入和输出函数,这些函数可分为字符输入/输出函数、格式化输入/输出函数、文件的输入/输出函数、文件定位函数、文件存取函数、错误控制函数;
++++A2.1、字符输入/输出函数
++++A2.2、格式化输入/输出函数
++++A2.3、文件输入/输出函数
++++A2.4、文件定位函数
++++A2.5、文件存取操作函数
++++A2.6、文件错误控制函数
++++A2.7、立钻哥哥带您stdio.h的综合应用
++A2.1、字符输入/输出函数
++A2.1、字符输入/输出函数 |
++A2.1、字符输入/输出函数
++++立钻哥哥:C语言中的字符输入/输出函数主要接受用户从键盘输入的字符或在屏幕上输出字符;
++++A2.1.1、getch/getche
++++A2.1.2、getchar
++++A2.1.3、gets
++++A2.1.4、putchar
++++A2.1.5、puts
++++A2.1.1、getch/getche
++++A2.1.1、getch/getche |
++A2.1.1、getch/getche
++++立钻哥哥:函数getch和函数getche的作用都是从键盘接受输入的字符;
int getch();int getche(); |
++++A2.1.2、getchar
++++A2.1.2、getchar |
++A2.1.2、getchar
++++立钻哥哥:函数getchar从键盘接受输入的字符并显示在屏幕上;
int getchar(); |
++++A2.1.3、gets
++++A2.1.3、gets |
++A2.1.3、gets
++++立钻哥哥:函数gets接受用户从键盘输入的一个字符串并存放到str指向的字符数组中;
char *gets(int *str); |
++++A2.1.4、putchar
++++A2.1.4、putchar |
++A2.1.4、putchar
++++立钻哥哥:函数putchar的作用是在屏幕上输出一个字符ch;
int putchar(int ch); |
++++A2.1.5、puts
++++A2.1.5、puts |
++A2.1.5、puts
++++立钻哥哥:函数puts的作用是在屏幕上输出多个字符串;
int puts(const char *str); |
++A2.2、格式化输入/输出函数
++A2.2、格式化输入/输出函数 |
++A2.2、格式化输入/输出函数
++++立钻哥哥:格式化输入/输出函数按照指定的格式(数据类型、对齐格式等)输出相应的数据;
++++A2.2.1、printf
++++A2.2.2、scanf
++++A2.2.3、sprintf
++++A2.2.4、sscanf
++++A2.2.5、vprintf
++++A2.2.6、vscanf
++++A2.2.1、printf
++++A2.2.1、printf |
++A2.2.1、printf
++++立钻哥哥:函数printf的作用是由format指定的格式控制下,将argument输出到屏幕上;
int printf(const char *format[,argument]...); |
++++A2.2.2、scanf
++++A2.2.2、scanf |
++A2.2.2、scanf
++++立钻哥哥:函数scanf的作用是从键盘接受输入的数据,并将其转换为相应的格式;
int scanf(const char *format[,argument]); |
++++A2.2.3、sprintf
++++A2.2.3、sprintf |
++A2.2.3、sprintf
++++立钻哥哥:函数sprintf的作用是将format指向的格式化数据输出到buffer指向的数组中;
int sprintf(char *buffer, const char *format[,argument]); |
++++A2.2.4、sscanf
++++A2.2.4、sscanf |
++A2.2.4、sscanf
++++立钻哥哥:函数sscanf的作用是从buffer指向的字符串中读取format指向格式的数据,存储到argument中;函数sscanf与函数scanf的作用类似;
int sscanf(char *buffer, const char *format[,argument]); |
++++A2.2.5、vprintf
++++A2.2.5、vprintf |
++A2.2.5、vprintf
++++立钻哥哥:函数vprintf的作用是在屏幕上输出格式化变长参数列表中的数据;
int vprintf(const char *format, va_list arg_ptr); |
++++A2.2.6、vscanf
++++A2.2.6、vscanf |
++A2.2.6、vscanf
++++立钻哥哥:函数vscanf从键盘读取格式化数据;
int vscanf(const char *format, va_list arg); |
++A2.3、文件输入/输出函数
++A2.3、文件输入/输出函数 |
++A2.3、文件输入/输出函数
++++立钻哥哥:文件输入/输出函数指的是从文件中读取数据或向文件写入数据的函数;这些函数的操作对象都是文件;
++++A2.3.1、fgetc/getc
++++A2.3.2、fgets
++++A2.3.3、fprintf
++++A2.3.4、fputc/putc
++++A2.3.5、fputs
++++A2.3.6、fread
++++A2.3.7、fscanf
++++A2.3.8、vfprintf
++++A2.3.9、vfscanf
++++A2.3.10、fwrite
++++A2.3.1、fgetc/getc
++++A2.3.1、fgetc/getc |
++A2.3.1、fgetc/getc
++++立钻哥哥:函数fgetc和函数getc接受stream指向的文件的当前位置的字符,并将文件位置指示器移动到下一个位置;fgetc函数与getc函数作用相同;
int fgetc(FILE *stream); |
++++A2.3.2、fgets
++++A2.3.2、fgets |
++A2.3.2、fgets
++++立钻哥哥:函数fgets从stream指向的文件中读取至多num-1个字符,并存入str指向的字符数组中;在字符被读入到数组后,自动在字符数组的最后添加一个空字符表示字符串的结束;
char *fgets(char *str, int num, FILE *stream); |
++++A2.3.3、fprintf
++++A2.3.3、fprintf |
++A2.3.3、fprintf
++++立钻哥哥:函数fprintf将格式化数据写入到stream指向的文件中;
int fprintf(FILE *stream, char *format[,argument]...) |
++++A2.3.4、fputc/putc
++++A2.3.4、fputc/putc |
++A2.3.4、fputc/putc
++++立钻哥哥:函数fputc和函数putc的作用都是输出一个字符到指定的文件中;
int fputc(int ch, FILE *stream); |
++++A2.3.5、fputs
++++A2.3.5、fputs |
++A2.3.5、fputs
++++立钻哥哥:函数fputs的作用是将str指向的字符串输出到stream指向的文件中;
int fputs(const char *str, FILE *stream); |
++++A2.3.6、fread
++++A2.3.6、fread |
++A2.3.6、fread
++++立钻哥哥:函数fread从stream指向的文件中读取count个字段,每个字段的大小为size字节,将其存放到buffer指向的字符数组中;
int fread(void *buffer, int size, int count, FILE *stream); |
++++A2.3.7、fscanf
++++A2.3.7、fscanf |
++A2.3.7、fscanf
++++立钻哥哥:函数fscanf从stream指向的文件中读取由format格式化的数据,并存入到参数argument列表中;
int fscanf(FILE *stream, const char *format[,argument]); |
++++A2.3.8、vfprintf
++++A2.3.8、vfprintf |
++A2.3.8、vfprintf
++++立钻哥哥:函数vfprintf根据format字符串格式化数据,并将该数据输出到stream指向的文件中;
int vfprintf(FILE *stream, const char *format, va_list arg); |
++++A2.3.9、vfscanf
++++A2.3.9、vfscanf |
++A2.3.9、vfscanf
++++立钻哥哥:函数vfscanf从stream指定的文件中读取格式化数据到可变参数列表arg_list中;
int vfscanf(FILE *stream, const char *format, va_list arg_list); |
++++A2.3.10、fwrite
++++A2.3.10、fwrite |
++A2.3.10、fwrite
++++立钻哥哥:函数fwrite将buffer指向的数组中的字符写入到stream指定的文件中;写入数据的长度是count*size;
int fwrite(void *buffer, int size, int count, FILE *stream); |
++A2.4、文件定位函数
++A2.4、文件定位函数 |
++A2.4、文件定位函数
++++立钻哥哥:文件中有一个文件位置指针,指向当前读/写字符所在位置;每次对文件进行读/写一次后,位置指针向后移动一个位置,指向下一个字符;为了读/写文件中的某一个字符,需要使用文件定位函数移动位置指针到相应的位置,然后才能读/写该字符;
++++A2.4.1、fseek
++++A2.4.2、ftell
++++A2.4.3、rewind
++++A2.4.1、fseek
++++A2.4.1、fseek |
++A2.4.1、fseek
++++立钻哥哥:函数fseek的作用是根据offset和origin设置stream指向的文件位置指针的位置;
int fseek(FILE *stream, long int offset, int origin); |
++++A2.4.2、ftell
++++A2.4.2、ftell |
++A2.4.2、ftell
++++立钻哥哥:函数ftell的作用是得到文件位置指针的当前值;这个值是以文件开头算起的字节数;
long int ftell(FILE *stream); |
++++A2.4.3、rewind
++++A2.4.3、rewind |
++A2.4.3、rewind
++++立钻哥哥:函数rewind的作用是将文件位置指针移动到文件的开始位置;另外,函数rewind还有清除错误标志和清除文件结束符的作用;
void rewind(FILE *stream); |
++A2.5、文件存取操作函数
++A2.5、文件存取操作函数 |
++A2.5、文件存取操作函数
++++立钻哥哥:除了文件的读取和定位操作外,C语言还提供了文件的存取操作;例如,打开文件、关闭文件、删除文件、重命名文件等;
++++A2.5.1、fclose
++++A2.5.2、fflush
++++A2.5.3、fopen
++++A2.5.4、remove
++++A2.5.5、rename
++++A2.5.1、fclose
++++A2.5.1、fclose |
++A2.5.1、fclose
++++立钻哥哥:函数fclose的作用是关闭stream指定的文件,并将缓冲区的内容全部写入该文件;
int fclose(FILE *stream); |
++++A2.5.2、fflush
++++A2.5.2、fflush |
++A2.5.2、fflush
++++立钻哥哥:函数fflush的作用是将缓冲区的内容写入到stream指定的文件中;如果stream指向输入文件,则缓冲区的内容将清除;
int fflush(FILE *stream); |
++++A2.5.3、fopen
++++A2.5.3、fopen |
++A2.5.3、fopen
++++立钻哥哥:函数fopen的作用是打开由filename指向的文件,具体的操作类型由mode定义;
FILE *fopen(const char *filename, const char *mode); |
++++A2.5.4、remove
++++A2.5.4、remove |
++A2.5.4、remove
++++立钻哥哥:函数remove的作用是删除由filename指向的文件;
int remove(const char *filename); |
++++A2.5.5、rename
++++A2.5.5、rename |
++A2.5.5、rename
++++立钻哥哥:函数rename的作用是将旧文件名(oldname)改为新文件名(newname);
int rename(const char *oldname, const char *newname); |
++A2.6、文件错误控制函数
++A2.6、文件错误控制函数 |
++A2.6、文件错误控制函数
++++立钻哥哥:在打开文件、对文件进行读取操作时,常常需要检查是否出现了错误,例如,打开的文件不存在、磁盘I/O错误等;这就需要使用C语言的文件错误控制函数进行判断;
++++A2.6.1、clearerr
++++A2.6.2、feof
++++A2.6.3、ferror
++++A2.6.1、clearerr
++++A2.6.1、clearerr |
++A2.6.1、clearerr
++++立钻哥哥:函数clearerr的作用是将stream指向的文件的错误标记重新设置为0(即关掉错误标记),文件结束指示器也被重置;
void clearerr(FILE *stream); |
++++A2.6.2、feof
++++A2.6.2、feof |
++A2.6.2、feof
++++立钻哥哥:函数feof的作用是检查文件位置指针是否到了文件末尾,如果到了文件末尾,则返回非0值;否则返回0;
int feof(FILE *stream); |
++++A2.6.3、ferror
++++A2.6.3、ferror |
++A2.6.3、ferror
++++立钻哥哥:函数ferror的作用是检查stream指向的文件在操作过程中是否出现了错误;
int ferror(FILE *stream); |
++A3、string.h
++A3、string.h |
++A3、string.h
++++立钻哥哥:头文件string.h定义了字符串和字符数组相关操作函数;它包含字符串比较函数、字符串复制函数、字符串连接函数、字符串查找函数、字符串转换函数等;
++++A3.1、字符串比较函数
++++A3.2、字符串复制函数
++++A3.3、字符串连接函数
++++A3.4、字符串查找函数
++++A3.5、字符串转换函数
++++A3.6、立钻哥哥整理的其他函数
++++A3.7、立钻哥哥带您string.h项目实战
++A3.1、字符串比较函数
++A3.1、字符串比较函数 |
++A3.1、字符串比较函数
++++立钻哥哥:C语言中的字符串比较函数其作用主要是比较两个字符串的大小;
++++A3.1.1、memcmp/memicmp
++++A3.1.2、strcmp/stricmp
++++A3.1.3、strncmp/strnicmp
++++A3.1.1、memcmp/memicmp
++++A3.1.1、memcmp/memicmp |
++A3.1.1、memcmp/memicmp
++++立钻哥哥:函数memcmp和函数memicmp的作用是比较buf1指向的前count个字符和buf2指向的前count个字符的大小;
int memcmp(const void *buf1, const void *buf2, unsigned count);int memicmp(const void *buf1, const void *buf2, unsigned count); |
++++说明:memicmp函数在比较时忽略字母的大小写;
++++A3.1.2、strcmp/stricmp
++++A3.1.2、strcmp/stricmp |
++A3.1.2、strcmp/stricmp
++++立钻哥哥:函数strcmp和函数stricmp的作用都是比较str1和str2两个字符串;从第1个字符串开始比较,直到遇到字符不相等或到达字符串末尾为止;
int strcmp(const char *str1, const char *str2);int stricmp(const char *str1, const char *str2); |
++++说明:stricmp函数不区分大小写;
++++A3.1.3、strncmp/strnicmp
++++A3.1.3、strncmp/strnicmp |
++A3.1.3、strncmp/strnicmp
++++立钻哥哥:函数strncmp和函数strnicmp都是比较长度不超过count的两个字符串的大小;如果两个字符串相等,则继续比较下面的字符,直到两个字符不相等、到达字符串末尾或count个字符比较完毕,才停止比较;
int strncmp(const char *str1, const char *str2, int count);int strnicmp(const char *str1, const char *str2, int count); |
++++说明:strnicmp函数不区分大小写;
++A3.2、字符串复制函数
++A3.2、字符串复制函数 |
++A3.2、字符串复制函数
++++立钻哥哥:字符串复制函数的作用是将字符从一个字符数组复制到另一个字符数组;
++++A3.2.1、memcpy
++++A3.2.2、memmove
++++A3.2.3、strcpy
++++A3.2.4、strncpy
++++A3.2.1、memcpy
++++A3.2.1、memcpy |
++A3.2.1、memcpy
++++立钻哥哥:函数memcpy的作用是从source指向的数组中复制count个字节到dest指向的数组中;
void *memcpy(void *dest, const void *source, unsigned count); |
++++A3.2.2、memmove
++++A3.2.2、memmove |
++A3.2.2、memmove
++++立钻哥哥:函数memmove的作用是从source指向的数组中复制count个字节到dest指向的数组中;
void *memmove(void *dest, const void *source, unsigned count); |
++++A3.2.3、strcpy
++++A3.2.3、strcpy |
++A3.2.3、strcpy
++++立钻哥哥:函数strcpy的作用是将source指向的字符串复制到dest指向的数组中,包括字符串的终结符;
char *strcpy(char *dest, const char *source); |
++++A3.2.4、strncpy
++++A3.2.4、strncpy |
++A3.2.4、strncpy
++++立钻哥哥:函数strncpy的作用是将source指向的前count个字符拷贝到dest字符数组中,如果count小于或等于source的长度,则空字符自动添加到dest末尾;如果count大于source的长度,则空字符被添加到dest的第count位置;
char *strncpy(char *dest, const char *source, unsigned count); |
++A3.3、字符串连接函数
++A3.3、字符串连接函数 |
++A3.3、字符串连接函数
++++立钻哥哥:字符串连接是指将一个字符串连接到另一个字符串的末尾使其构成一个字符串;
++++A3.3.1、strcat
++++A3.3.2、strncat
++++A3.3.1、strcat
++++A3.3.1、strcat |
++A3.3.1、strcat
++++立钻哥哥:函数strcat的作用是将source指向的字符串连接到dest指向的字符串的末尾,并以空字符结束dest;dest指向的字符串最后的空字符被source的第1个字符覆盖掉;
char *strcat(char *dest, const char *source); |
++++A3.3.2、strncat
++++A3.3.2、strncat |
++A3.3.2、strncat
++++立钻哥哥:函数strncat的作用是将source指向的前count个字符连接到dest数组中,包括空字符;如果source指向的字符串长度小于count,则将source的字符串连接到dest末尾;
char *strncat(char *dest, char *source, unsigned count); |
++A3.4、字符串查找函数
++A3.4、字符串查找函数 |
++A3.4、字符串查找函数
++++立钻哥哥:字符串查找指的是在指定的字符串中查找字符或字符串;在程序设计过程中,经常会进行字符或字符串查找操作,C语言提供了相关的查找函数;
++++A3.4.1、memchr
++++A3.4.2、strchr
++++A3.4.3、strstr
++++A3.4.4、strtok
++++A3.4.1、memchr
++++A3.4.1、memchr |
++A3.4.1、memchr
++++立钻哥哥:函数memchr的作用是在由buffer指向的前count个字节中查找第1次遇到的值为c的数据(字符);如果找到c或前count字节扫描完毕,则查找结束;
void *memchr(const void *buffer, int c, unsigned count); |
++++A3.4.2、strchr
++++A3.4.2、strchr |
++A3.4.2、strchr
++++立钻哥哥:函数strchr的作用是在由str指向的字符串中查找字符第一次出现的字符ch;
char *strchr(const char *str, int ch); |
++++A3.4.3、strstr
++++A3.4.3、strstr |
++A3.4.3、strstr
++++立钻哥哥:函数strstr的作用是在由str1指向的字符串中查找第1次出现字符串str2;
char *strstr(const char *str1, const char *str2); |
++++A3.4.4、strtok
++++A3.4.4、strtok |
++A3.4.4、strtok
++++立钻哥哥:函数strtok的作用是利用delimiters字符串中的字符分解字符串str;
char *strtok(char *str, const char *delimiters); |
++++说明:strtok函数实际上修改了str指向的字符串;每次找到一个分隔符后,一个空字符就被放置在分隔符处;strtok函数返回该字符串的指针,就可以根据该指针输出分隔后的字符串了;
++A3.5、字符串转换函数
++A3.5、字符串转换函数 |
++A3.5、字符串转换函数
++++立钻哥哥:字符串转换包括将大写字母转换为小写字母、将小写字母转换为大写字母、将字符串逆置;
++++A3.5.1、strlwr
++++A3.5.2、strrev
++++A3.5.3、strupr
++++A3.5.1、strlwr
++++A3.5.1、strlwr |
++A3.5.1、strlwr
++++立钻哥哥:函数strlwr的作用是将str指向的字符串中的大写字母转换为小写字母;
char *strlwr(char *str); |
++++A3.5.2、strrev
++++A3.5.2、strrev |
++A3.5.2、strrev
++++立钻哥哥:函数strrev的作用是将str指向的字符串中字符颠倒过来;
char *strrev(char *str); |
++++A3.5.3、strupr
++++A3.5.3、strupr |
++A3.5.3、strupr
++++立钻哥哥:函数strupr的作用是将str指向的字符串中的小写字母转换为大写字母;
char *strupr(char *str); |
++A3.6、立钻哥哥整理的其他函数
++A3.6、立钻哥哥整理的其他函数 |
++A3.6、立钻哥哥整理的其他函数
++++立钻哥哥:C语言还提供了其他函数,例如,求字符串的长度、将字符串中的某些区域设置为指定的字符等;
++++A3.6.1、memset
++++A3.6.2、strlen
++++A3.6.1、memset
++++A3.6.1、memset |
++A3.6.1、memset
++++立钻哥哥:函数memset的作用是将buf指向的字符串中的前count个字节都设置为value;
void *memset(void *buf, int value, unsigned count); |
++++A3.6.2、strlen
++++A3.6.2、strlen |
++A3.6.2、strlen
++++立钻哥哥:函数strlen的作用是求以空字符结尾的字符串str的长度;
unsigned strlen(const char *str); |
++A4、stdlib.h
++A4、stdlib.h |
++A4、stdlib.h
++++立钻哥哥:头文件stdlib.h包含了字符串转换函数、动态内存管理函数、随机数生成函数、过程控制函数、查找和排序函数;字符串转换函数可以将字符串转换为各种数值类型的数据,也可以将各种类型的数值转换为字符串;动态内存分配函数主要用来动态分配内存单元和释放内存单元;过程控制函数用来控制当前执行的进程;
++++A4.1、字符串转换函数
++++A4.2、动态内存管理函数
++++A4.3、随机数生成函数
++++A4.4、查找和排序函数
++++A4.5、过程控制函数
++A4.1、字符串转换函数
++A4.1、字符串转换函数 |
++A4.1、字符串转换函数
++++立钻哥哥:C语言中的字符串转换函数主要有atof函数、atoi函数、atol函数、itoa函数和ltoa函数,分别用来将字符串转换为双精度类型、将字符串转换为整数、将字符串转换为长整型、将整型转换为字符串、将长整型转换为字符串;
++++A4.1.1、atof
++++A4.1.2、atoi
++++A4.1.3、atol
++++A4.1.4、itoa
++++A4.1.5、ltoa
++++A4.1.1、atof
++++A4.1.1、atof |
++A4.1.1、atof
++++立钻哥哥:函数atof的作用是将str指向的字符串转换为双精度浮点数;
double atof(const char *str); |
++++A4.1.2、atoi
++++A4.1.2、atoi |
++A4.1.2、atoi
++++立钻哥哥:函数atoi的作用是将字符串str转换为整型数值;
int atoi(const char *str); |
++++A4.1.3、atol
++++A4.1.3、atol |
++A4.1.3、atol
++++立钻哥哥:函数atol的作用是将字符串str转换为对应的长整型数据;
long int atol(const char *str); |
++++A4.1.4、itoa
++++A4.1.4、itoa |
++A4.1.4、itoa
++++立钻哥哥:函数itoa的作用是将整数value转换为相应的字符串str;其中,base表示要转换的进制;
char *itoa(int value, char *str, int base); |
++++A4.1.5、ltoa
++++A4.1.5、ltoa |
++A4.1.5、ltoa
++++立钻哥哥:函数ltoa的作用是将长整型数value转换为相应的字符串str;其中,base表示要转换的进制;
char *ltoa(long value, char *str, int base); |
++A4.2、动态内存管理函数
++A4.2、动态内存管理函数 |
++A4.2、动态内存管理函数
++++立钻哥哥:动态内存管理函数包括calloc函数、malloc函数、realloc函数和free函数;
++++A4.2.1、calloc
++++A4.2.2、free
++++A4.2.3、malloc
++++A4.2.4、realloc
++++A4.2.5、立钻哥哥带您“动态内存管理函数”实战
++++Tips:“动态内存管理”是C/C++语言的魅力所在,也是把双刃剑,使用“C/C++”的开发者都是具有探索精神的,欢迎加入“C/C++”开发中;
++++A4.2.1、calloc
++++A4.2.1、calloc |
++A4.2.1、calloc
++++立钻哥哥:函数calloc的作用是分配一块内存空间,内存空间的大小是num*size;其中,num表示每个元素的个数,size表示每个元素所占用的字节数;
void *calloc(unsigned num, unsigned size); |
++++说明:使用calloc函数分配内存单元后,需要通过判断函数返回值查看是否分配内存成功;
++++A4.2.2、free
++++A4.2.2、free |
++A4.2.2、free
++++立钻哥哥:函数free的作用是释放ptr指向的内存空间,以使这些内存成为可用空间再次被分配;
void *free(void *ptr); |
++++注意1:使用free函数将内存空间释放后,ptr仍然指向原来的内存空间,只是该内存空间中的内容变得无效,所以,记得:ptr = NULL; 否则会出现野指针哟!
++++注意2:在使用完由malloc函数、realloc函数和calloc函数申请的空间后,需要调用free函数将空间释放掉;一般malloc/free是成对出现的,不然就会出现内存泄露的呢!
++++A4.2.3、malloc
++++A4.2.3、malloc |
++A4.2.3、malloc
++++立钻哥哥:函数malloc的作用是动态分配一块大小为size字节的内存空间;
void *malloc(unsigned size); |
++++说明:使用malloc函数申请的内存空间中的内容不会被初始化,其中的数据是不确定的;
++++A4.2.4、realloc
++++A4.2.4、realloc |
++A4.2.4、realloc
++++立钻哥哥:函数realloc的作用是将ptr指向的已分配内存空间的大小变为newsize字节,newsize可以大于,也可以小于原来的内存大小;
void *realloc(void *ptr, unsigned newsize); |
++++说明1:如果realloc函数为了增加内存空间的大小而改变了内存空间的位置,原来的内存空间内容将被拷贝到新内存空间中,数据并不会丢失;
++++说明2:如果ptr为NULL,则realloc函数的作用于malloc函数等价,系统将分配一块新的内存空间并返回指向该内存空间开始位置的指针;
++++说明3:如果newsize的值为0,则内存空间将被回收并返回一个空指针,相当于调用了free函数;
++A4.3、随机数生成函数
++A4.3、随机数生成函数 |
++A4.3、随机数生成函数
++++立钻哥哥:C语言提供的随机数生成函数主要有rand函数、randdom函数、randomize函数和srand函数;
++++A4.3.1、rand
++++A4.3.2、random/randomize
++++A4.3.3、srand
++++A4.3.1、rand
++++A4.3.1、rand |
++A4.3.1、rand
++++立钻哥哥:函数rand的作用是产生0~RAND_MAX之间的整数;
int rand(); |
++++A4.3.2、random/randomize
++++A4.3.2、random/randomize |
++A4.3.2、random/randomize
++++立钻哥哥:函数random的作用是产生0~num之间的整数;函数randomize的作用是初始化随机数发生器,使random函数每次产生不同的随机数;
int random(int num);void randomize(); |
++++说明:为了在调用random函数时,每次产生不同的随机数,需要调用函数randomize,初始化随机数发生器;
++++A4.3.3、srand
++++A4.3.3、srand |
++A4.3.3、srand
++++立钻哥哥:函数srand的作用是利用参数seed初始化随机数发生器;常常与rand函数配合使用;
void srand(unsigned seed); |
++++说明:srand函数的参数seed不同,rand函数产生的随机数序列也不相同;为了得到不同的随机数,可以用时间函数time(NULL)作为srand函数的参数:srand(time(NULL));(获取当前的时间作为随机数的种子);
++A4.4、查找和排序函数
++A4.4、查找和排序函数 |
++A4.4、查找和排序函数
++++立钻哥哥:为了程序设计方便,ANSI C还提供了查找函数和排序函数;这样在程序设计过程中,就不需要自己编写查找函数和排序函数了,直接调用C提供的这些函数即可;
++++A4.4.1、bsearch
++++A4.4.2、qsort
++++A4.4.3、立钻哥哥带您“查找和排序函数”实战
++++A4.4.1、bsearch
++++A4.4.1、bsearch |
++A4.4.1、bsearch
++++立钻哥哥:函数bsearch的作用是在由base指向的数组中进行折半查找,返回找到的关键字为key的元素的指针;其中,num是元素的个数,size是每个元素所占的字节数;
void *bsearch(const void *key, const void *base, unsigned num, unsigned size, int (*compare)(const void *, const void *)); |
++++说明1:参数compare,函数指针,该函数用来比较两个元素关键字的大小;compare函数的原型:int compare(const void *elem1, const void *elem2);;
++++说明2:使用bsearch函数查找数组中的元素时,数组中的元素必须是按照升序排列的;
++++A4.4.2、qsort
++++A4.4.2、qsort |
++A4.4.2、qsort
++++立钻哥哥:函数qsort的作用是使用快速排序算法对base指向的数组进行排序;
void qsort(void *base, unsigned num, unsigned size, int(*compare)(const void *, const void *)); |
++++说明1:参数compare,函数指针,该函数用来比较两个元素关键字的大小;compare函数的原型:int compare(const void *elem1, const void *elem2);;
++++说明2:如果要排序的元素是整型,则在调用compare函数时,需要将compare函数中的两个参数转换为整型后,再进行相减;
++++A4.4.3、立钻哥哥带您“查找和排序函数”实战
++++A4.4.3、立钻哥哥带您“查找和排序函数”实战 |
++A4.4.3、立钻哥哥带您“查找和排序函数”实战
++++立钻哥哥:“实战是关键”,学些C/C++过程中,就是需要反复敲代码的;
| //立钻哥哥:随机数生成函数和查找排序函数综合应用实战 //实战需求:利用随机数生成函数初始化数组,并利用qsort函数对数组中的元素分别进行升序排列和降序排列,最后利用bsearch函数查找数组中的元素 #include <stdio.h> #include <stdlib.h>
#define N 10
//随机产生范围为[start, end]的元素序列 void InitArray(int b[], int start, int end){ int i, j, flag; srand(time(NULL)); ... ... }
//比较两个元素的大小(升序) int ascending(const void *a, const void *b){ return (*(int*)a - *(int*)b); }
//比较两个元素的大小(降序) int descending(const void *a, const void *b){ return (*(int*)b - *(int*)a); }
void main() { int a[N], key; int *p;
InitArray(a, N, 100, 200);
qsort(a, N, sizeof(int), ascending);
p = (int*)bsearch(&key, a, N, sizeof(int), ascending);
... ... } ++++说明:这里立钻哥哥只是提供了一些思路,还有相关细节就不再赘述了; |
++A4.5、过程控制函数
++A4.5、过程控制函数 |
++A4.5、过程控制函数
++++立钻哥哥:C语言提供了一些用于控制程序执行的函数;例如,exit函数用于终止正在执行的程序,system函数用于执行系统命令;在C语言中,这些函数的声明包含在头文件stdlib.h和process.h中;在C++语言中,这些函数包含在头文件stdlib.h中;
++++A4.5.1、abort
++++A4.5.2、exit
++++A4.5.3、system
++++A4.5.1、abort
++++A4.5.1、abort |
++A4.5.1、abort
++++立钻哥哥:函数abort的作用是以非正常的方式终止当前的进程;
void abort(); |
++++说明1:abort函数并不会将控制权交给调用过程;在默认情况下,该函数终止当前的进程并返回一个错误码3;
++++说明2:abort函数并不会进行常规的清理工作,如释放内存等;
++++A4.5.2、exit
++++A4.5.2、exit |
++A4.5.2、exit
++++立钻哥哥:函数exit的作用是使程序正常终止;
void exit(int status); |
++++说明1:参数status,传递给父进程的状态值;在通常情况下,如果status为0,则说明程序正常终止;否则,说明程序存在错误;
++++说明2:exit函数将使所有已经注册的程序逆序终止;exit函数关闭所有打开的文件,并删除临时文件,最后将控制权交给主程序;
++++A4.5.3、system
++++A4.5.3、system |
++A4.5.3、system
++++立钻哥哥:函数system的作用是在DOS或cmd.exe中执行command命令;
int system(const char *command); |
++++说明1:参数command,要执行的系统命令;
++++说明2:system函数也可以修改文件的属性,例如,将文件myfile.txt修改为只读属性:system(“attrib +r d:\myfile.txt”);;
++A5、math.h
++A5、math.h |
++A5、math.h
++++立钻哥哥:头文件math.h包含了三角函数、指数和对数函数、幂指数和开方函数、其他数学函数;C++兼容了math.h库函数,其用法与C相同;
++++A5.1、三角函数
++++A5.2、指数和对数函数
++++A5.3、幂指数和开方函数
++++A5.4、绝对值函数
++++A5.5、立钻哥哥整理的其他数学函数
++++A5.6、立钻哥哥带您math.h实战
++A5.1、三角函数
++A5.1、三角函数 |
++A5.1、三角函数
++++立钻哥哥:C语言中的三角函数主要有cos函数、sin函数、tan函数、acos函数、asin函数和atan函数,分别用来求角度的余弦值、正弦值、正切值、反余弦值、反正弦值和反正切值;
++++A5.1.1、cos
++++A5.1.2、sin
++++A5.1.3、tan
++++A5.1.4、acos
++++A5.1.5、asin
++++A5.1.6、atan
++++A5.1.1、cos
++++A5.1.1、cos |
++A5.1.1、cos
++++立钻哥哥:函数cos的作用是求x的余弦值;
double cos(double x); |
++++A5.1.2、sin
++++A5.1.2、sin |
++A5.1.2、sin
++++立钻哥哥:函数sin的作用是求x的正弦值;
double sin(double x); |
++++A5.1.3、tan
++++A5.1.3、tan |
++A5.1.3、tan
++++立钻哥哥:函数tan的作用是求x的正切值;
double tan(double x); |
++++A5.1.4、acos
++++A5.1.4、acos |
++A5.1.4、acos
++++立钻哥哥:函数acos的作用是求x的反余弦值;
double acos(double x); |
++++A5.1.5、asin
++++A5.1.5、asin |
++A5.1.5、asin
++++立钻哥哥:函数asin的作用是求x的反正弦值;
double asin(double x); |
++++A5.1.6、atan
++++A5.1.6、atan |
++A5.1.6、atan
++++立钻哥哥:函数atan的作用是求x的反正切值;
double atan(double x); |
++A5.2、指数和对数函数
++A5.2、指数和对数函数 |
++A5.2、指数和对数函数
++++立钻哥哥:指数和对数函数主要包括exp函数、log函数、log10函数;
++++A5.2.1、exp
++++A5.2.2、log
++++A5.2.3、log10
++++A5.2.1、exp
++++A5.2.1、exp |
++A5.2.1、exp
++++立钻哥哥:函数exp的作用是求以自然数e为底的指数即e.x的值;
double exp(double x); |
++++A5.2.2、log
++++A5.2.2、log |
++A5.2.2、log
++++立钻哥哥:函数log的作用是求x的自然对数;
double log(double x); |
++++A5.2.3、log10
++++A5.2.3、log10 |
++A5.2.3、log10
++++立钻哥哥:函数log10的作用是返回x的对数值;
double log10(double x); |
++A5.3、幂指数和开方函数
++A5.3、幂指数和开方函数 |
++A5.3、幂指数和开方函数
++++立钻哥哥:C语言提供的幂指数函数和开方函数主要有pow函数、pow10函数、sqrt函数;
++++A5.3.1、pow
++++A5.3.2、pow10
++++A5.3.3、sqrt
++++A5.3.1、pow
++++A5.3.1、pow |
++A5.3.1、pow
++++立钻哥哥:函数pow的作用是求以base为底exp为指数的base.exp的值;
double pow(double base, double exp); |
++++A5.3.2、pow10
++++A5.3.2、pow10 |
++A5.3.2、pow10
++++立钻哥哥:函数pow10的作用是计算10.exp的值;
double pow10(int exp); |
++++A5.3.3、sqrt
++++A5.3.3、sqrt |
++A5.3.3、sqrt
++++立钻哥哥:函数sqrt的作用是求x的平方根;
double sqrt(double x); |
++A5.4、绝对值函数
++A5.4、绝对值函数 |
++A5.4、绝对值函数
++++立钻哥哥:C语言专门提供了几个绝对值函数:abs函数、fabs函数和labs函数;
++++A5.4.1、abs
++++A5.4.2、fabs
++++A5.4.3、labs
++++A5.4.1、abs
++++A5.4.1、abs |
++A5.4.1、abs
++++立钻哥哥:函数abs的作用是求x的绝对值;
int abs(int x); |
++++A5.4.2、fabs
++++A5.4.2、fabs |
++A5.4.2、fabs
++++立钻哥哥:函数fabs的作用是求浮点数x的绝对值;
double fabs(double x); |
++++A5.4.3、labs
++++A5.4.3、labs |
++A5.4.3、labs
++++立钻哥哥:函数labs的作用是求x的绝对值;
long labs(long x); |
++A5.5、立钻哥哥整理的其他数学函数
++A5.5、立钻哥哥整理的其他数学函数 |
++A5.5、立钻哥哥整理的其他数学函数
++++立钻哥哥:C语言还提供了floor函数、frexp函数、hypot函数等,这些函数分别用来求不大于x的最大整数、将一个浮点数表示为科学计数法的形式、根据直角边求斜边;
++++A5.5.1、floor
++++A5.5.2、fmod
++++A5.5.3、frexp
++++A5.5.4、hypot
++++A5.5.5、modf
++++A5.5.6、poly
++++A5.5.1、floor
++++A5.5.1、floor |
++A5.5.1、floor
++++立钻哥哥:函数floor的作用是求不大于x的最大整数;
double floor(double x); |
++++A5.5.2、fmod
++++A5.5.2、fmod |
++A5.5.2、fmod
++++立钻哥哥:函数fmod的作用是求x/y的余数;
double fmod(double x, double y); |
++++A5.5.3、frexp
++++A5.5.3、frexp |
++A5.5.3、frexp
++++立钻哥哥:函数frexp的作用是将x分解为一个从0.5到小于1之间的浮点数和一个整型数;其中,前者称为尾数,由函数返回;后者称为指数,存放在变量exp中;
double frexp(double x, int *exp); |
++++A5.5.4、hypot
++++A5.5.4、hypot |
++A5.5.4、hypot
++++立钻哥哥:函数hypot的作用是由直角边x和y得到斜边的长度;
double hypot(double x, double y); |
++++A5.5.5、modf
++++A5.5.5、modf |
++A5.5.5、modf
++++立钻哥哥:函数modf的作用是将x分解为两个部分:整数部分和小数部分;其中,整数部分存入*intpartptr中,小数部分通过函数返回;
double modf(double x, double *intpart); |
++++A5.5.6、poly
++++A5.5.6、poly |
++A5.5.6、poly
++++立钻哥哥:函数poly的作用是根据数组c提供的多项式系数,求x的n次多项式的值;
double poly(double x, int n, double c[]); |
++++说明:如果n=3,则该多项式的值的计算方法是:c[3]x.3+c[2]x.2+c[1]x+c[0];;
++A6、conio.h
++A6、conio.h |
++A6、conio.h
++++立钻哥哥:conio是Console Input/Output的缩写,头文件conio.h定义了通过控制台进行数据输入和输出的函数;它包含了字符输入/输出函数、屏幕操作函数、文本属性函数、文本拷贝函数等;
++++注意:ANSI C++并没有兼容conio.h库函数;
++++Tips:钻哥说了,C++没有兼容的C库可以先不拓展,呵呵,我们要把有限的时间和精力放在通用性的技术上嘛!
++++A6.1、字符输入/输出函数
++++A6.2、屏幕操作函数
++++A6.3、文本属性函数
++++A6.4、文本赋值函数
====>立钻哥哥后期还会推出《Linux C》,这里将带大家熟悉一些比较通用性的C库;请关注“C++C铸就生存利器”分类,这里会不断推出基于C/C++技术的应用,比如Linux系统编程、C++游戏服务器等;
++++【C++C铸就生存利器】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_9325802.html
++A7、graphics.h
++A7、graphics.h |
++A7、graphics.h
++++立钻哥哥:头文件graphics.h包含了丰富的图形函数,主要可以分为以下几类:图形模式函数、图形属性函数、画点类函数、画线类函数、图形填充函数、图形模式下的文本函数和屏幕操作函数;
++++注意:ANSI C和ANSI C++并没有定义graphics.h库函数,它是Turbo C开发环境下定义的库函数;
++++Tips:钻哥说了,C++没有兼容的C库可以先不拓展,呵呵,我们要把有限的时间和精力放在通用性的技术上嘛!
++++A7.1、图形模式函数
++++A7.2、图形属性函数
++++A7.3、画点类函数
++++A7.4、画线类函数
++++A7.5、图形填充函数
++++A7.6、图形模式下的文本函数
++++A7.7、屏幕操作函数
++++立钻哥哥:这个graphics.h库给我们一个信息:C/C++是可以开发图形的,如果您不熟悉Shader编程(GLSL、HLSL、Cg),可以利用这个库在TuboC开发环境下试一下呢,如果您还是想挑战一下Shader编程,您可以查看“shader编程”分类,这里介绍了Shader编程相关技术;
++++【Shader编程】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_7570174.html
++A8、stdarg.h
++A8、stdarg.h |
++A8、stdarg.h
++++立钻哥哥:stdarg是standard arguments的缩写,头文件stdar.h中定义的函数(宏)是为接受不定量参数;头文件stdarg.h主要包括了3个宏:va_arg宏、va_end宏和va_start宏;
++++Tips:ANSI C++也兼容了stdarg.h库函数;
++++A8.1、va_arg
++++A8.2、va_end
++++A8.3、va_start
++++A8.1、va_arg
++++A8.1、va_arg |
++A8.1、va_arg
++++立钻哥哥:宏va_arg的作用是返回argptr指向的可变参数列表中的参数,并使argptr指向可变参数列表中的下一个参数;
type va_arg(va_list argptr, type); |
++++[参数argptr]:指向可变参数列表中的参数,类型为va_list,va_list是控制可变参数信息的类型;
++++[参数type]:类型名,表示要提取的参数类型;
++++[函数返回值]:该宏返回argptr指向的可变参数列表中的参数的参数,参数类型为argptr指向的类型;
++++说明1:va_list是可变参数列表类型,其中,va是variable argument的缩写;
++++A8.2、va_end
++++A8.2、va_end |
++A8.2、va_end
++++立钻哥哥:宏va_end的作用是终止使用可变参数列表argptr;
void va_end(va_list argptr); |
++++说明:调用va_end宏后,argptr变得无效;一般情况下,va_start宏与va_end宏成对使用,va_start宏用来初始化可变参数,va_end宏用来结束可变参数的使用;
++++A8.3、va_start
++++A8.3、va_start |
++A8.3、va_start
++++立钻哥哥:宏va_start的作用是初始化可变参数列表对象argptr,使argptr指向可变参数列表中的第一个可选参数;prev_param是位于第一个可变参数之前的固定参数;
void va_start(va_list argptr, prev_param); |
++函数范例
++++立钻哥哥:计算浮点数的平均数;
| #include <stdio.h> #include <stdarg.h>
void MyAverage(int amount, ...) { int i; double val, total = 0.0; va_list arg;
va_start(arg, amount); for(i = 0, i < amount; i++){ val = va_arg(arg, double); total += val; } va_end(arg); }
void Main() { MyAverage(3, 12.0, 20.0, 44.0); } |
++A9、time.h
++A9、time.h |
++A9、time.h
++++立钻哥哥:头文件time.h主要包含了时间日期操作和转换函数;
++++Tips:ANSI C++兼容了time.h库函数;
++++A9.1、时间操作函数
++++A9.2、时间格式转换函数
++A9.1、时间操作函数
++A9.1、时间操作函数 |
++A9.1、时间操作函数
++++立钻哥哥:时间操作函数主要包括clock函数、difftime函数、time函数;
++++A9.1.1、clock
++++A9.1.2、difftime
++++A9.1.3、time
++++A9.1.1、clock
++++A9.1.1、clock |
++A9.1.1、clock
++++立钻哥哥:函数clock的作用是返回CPU计时单元;
long clock(); |
| //立钻哥哥:利用clock函数进行倒计时 void MyWait(int second) { clock_t end; end = clock() + second * CLOCKS_PER_SEC;
while(clock() < end){ } } |
++++[函数的返回值]:函数返回开启这个程序进程到程序中调用clock函数时之间的CPU时钟计时单元;
++++A9.1.2、difftime
++++A9.1.2、difftime |
++A9.1.2、difftime
++++立钻哥哥:函数difftime的作用是返回time1到time2所经过的秒数;
double difftime(time_t time2, time_t time1); |
++++A9.1.3、time
++++A9.1.3、time |
++A9.1.3、time
++++立钻哥哥:函数time的作用是获取以秒为单位,格林尼治时间1970年1月1日00:00:00开始计时的当前时间值,并将它存放在timer所指向的内存单元中;
time_t time(time_t *timer); |
++++说明:time函数的参数和返回值类型都是time_t,实际上是long类数据;
++A9.2、时间格式转换函数
++A9.2、时间格式转换函数 |
++A9.2、时间格式转换函数
++++立钻哥哥:时间格式转换函数主要包括asctime函数、ctime函数、gmtime函数、localtime函数、mktime函数、strftime函数;
++++A9.2.1、asctime
++++A9.2.2、ctime
++++A9.2.3、gmtime
++++A9.2.4、localtime
++++A9.2.5、mktime
++++A9.2.6、strftime
++++A9.2.1、asctime
++++A9.2.1、asctime |
++A9.2.1、asctime
++++立钻哥哥:函数asctime的作用是把以struct tm格式表示的时间转换为以下字符串形式:星期 月 日 小时:分:秒 年;
char *asctime(struct tm *timeptr); |
++++A9.2.2、ctime
++++A9.2.2、ctime |
++A9.2.2、ctime
++++立钻哥哥:函数ctime的作用是将参数timer表示的时间转换为下列形式的字符串:星期 月 日 小时:分:秒 年;
char *ctime(time_t *timer); |
++++说明:ctime函数直接将time_t表示的时间转换为字符串形式;astime函数需要先将time_t表示的时间转换为struct tm格式,然后调用asctime函数将时间转换为字符串形式;
++++A9.2.3、gmtime
++++A9.2.3、gmtime |
++A9.2.3、gmtime
++++立钻哥哥:函数gmtime的作用是将time_t表示的时间转换为格林尼治时间,函数的返回值是一个指向struct tm时间结构的指针;
struct tm *gmtime(const time_t *timer); |
++++A9.2.4、localtime
++++A9.2.4、localtime |
++A9.2.4、localtime
++++立钻哥哥:函数localtime的作用是返回指向struct tm时间结构的指针;
struct tm *localtime(const time_t *timer); |
++++A9.2.5、mktime
++++A9.2.5、mktime |
++A9.2.5、mktime
++++立钻哥哥:函数mktime的作用是将参数timeptr所指向的struct tm结构数据转换为从公元1970年1月1日0时0分0秒开始到现在所经过的秒数;
time_t mktime(struct tm *timeptr); |
++++A9.2.6、strftime
++++A9.2.6、strftime |
++A9.2.6、strftime
++++立钻哥哥:函数strftime的作用是将格式字符串存放在ptr指向的内存单元中;其中,maxsize表示字符的最大个数;format表示格式控制,与printf函数中的含义相同;timeptr表示要格式化的struct tm结构,包含日期时间信息;
size_t strftime(char *ptr, size_t maxsize, const char *format, const struct tm *timeptr); |
++++说明:strftime函数是ANSI C++增加的标准函数,在ANSI C中并没有包含该函数;
++A10、dir.h
++A10、dir.h |
++++立钻哥哥:头文件dir.h主要包含了一些磁盘目录操作函数,这些函数都不是ANSI C和ANSI C++定义的标准函数,但是Turbo C包含了这些函数的定义,可以很容易地对磁盘目录和文件进行操作;
++++Tips:ANSI C和ANSI C++并没有兼容dir.h库函数;
++++Tips:钻哥说了,C++没有兼容的C库可以先不拓展,呵呵,我们要把有限的时间和精力放在通用性的技术上嘛!
++++A10.1、目录操作函数
++++A10.2、文件查找函数
++++立钻哥哥:对磁盘目录和文件等的操作,我们会拓展为《LinuxC函数与算法》进行学习;
++++《LinuxC函数与算法》:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104076473

++A11、立钻哥哥带您了解其他C函数库
++A11、立钻哥哥带您了解其他C函数库 |
++A11、立钻哥哥带您了解其他C函数库
++++立钻哥哥:C语言中比较常用的函数还有abort函数、exit函数、sleep函数、system函数、bioskey函数、geninterrupt函数、int86函数;
++++A11.1、abort
++++A11.2、exit
++++A11.3、sleep
++++A11.4、system
++++A11.5、bioskey
++++A11.6、geninterrupt
++++A11.7、int86
++++A11.1、abort
++++A11.1、abort |
++A11.1、abort
++++立钻哥哥:函数abort的作用是使程序立即终止运行;
void abort(); |
++++A11.2、exit
++++A11.2、exit |
++A11.2、exit
++++立钻哥哥:函数exit的作用是使程序立即终止运行;
void exit(int status); |
++++A11.3、sleep
++++A11.3、sleep |
++A11.3、sleep
++++立钻哥哥:函数sleep的作用是使程序暂停运行time秒时间;
void sleep(unsigned time); |
++++A11.4、system
++++A11.4、system |
++A11.4、system
++++立钻哥哥:函数system的作用是在C程序中执行DOS系统命令;
int system(char *command); |
++++A11.5、bioskey
++++A11.5、bioskey |
++A11.5、bioskey
++++立钻哥哥:函数bioskey的作用是判断键盘上的某个键是否被按下;
int bioskey(int cmd); |
++++A11.6、geninterrupt
++++A11.6、geninterrupt |
++A11.6、geninterrupt
++++立钻哥哥:函数geninterrupt的作用是产生一个软中断;
void geninterrupt(int intr_num); |
++++A11.7、int86
++++A11.7、int86 |
++A11.7、int86
++++立钻哥哥:函数int86的作用是执行int_num指定的软中断;其中,in_regs是输入参数,out_regs是输出参数;
int int86(int int_num, union REGS *in_regs, union REGS *out_regs); |
++++说明:int86函数和geninterrupt函数都是用来调用系统中断的,它们的作用是等价的;但是,利用int86函数可以得到寄存器的各个输出参数值;
++++立钻哥哥:《C/C++函数与算法(C独立篇)》基本整理完毕了,这些C基本是在Windows系统下广泛使用;在Linux系统下,我们会独立出《Linux C函数与算法》学习;也会推出“C++”、“算法”等专题,以“姊妹篇”的方式进行推广使用;
++++【C/C++函数与算法(C库独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104026090
++++【C/C++函数与算法(C++库独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104062275
++++【C/C++函数与算法(算法独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104062527
++++【C/C++函数与算法(Linux C独立篇)】:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/104076473
++++【C++C铸就生存利器】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.youkuaiyun.com/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥优快云空间】:https://blog.youkuaiyun.com/VRunSoftYanlz/
++++VR云游戏=Unity+SteamVR+云技术+5G+AI;(说明:AI人工智能不是我们的主要研究技术,只是了解一下,领略一下有风的感觉!但是,VR是我们的研究重点)

@@提示:有些博客可能只是开了头,如果感兴趣的同学,可以“点赞”或“评论区留言”,只要关注的同学多了,那就会继续完善哟!(“++==”,表示没有写完的,如果关注度不高就不完善了;“++ok++”,表示此篇博客已经完成,是阶段性完整的!)
【XR游戏开发QQ群:784477094】

++立钻哥哥推荐的拓展学习链接(Link_Url):
| 立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.youkuaiyun.com/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.youkuaiyun.com/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/87303828
++++插件<Obi Rope>:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/83963905
++++计算机组成原理(教材篇):https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.youkuaiyun.com/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.youkuaiyun.com/VRunSoftYanlz/
--_--VRunSoft:lovezuanzuan--_--




被折叠的 条评论
为什么被折叠?



