字符串操作函数实现strcpy() strcmp()...
来源:互联网 发布:手机掌上贵金属软件 编辑:程序博客网 时间:2024/05/19 00:52
strcpy() 复制字符串
char* my_strcpy(char* str1, const char* str2){char* ret = str1;assert(str1 != NULL);assert(src != NULL);while ((*str1++ = *str2++) != '\0'){;}return ret;}
strcat() 添加字符串
char* my_strcat(char *str1, char *str2){char* ret = str1;assert(dest != NULL);assert(src != NULL);while (*str1 != '\0') str1++;while (*str2 != '\0') *str1++ = *str2++;*str1 = '\0';return ret;}strcmp() 字符串比较
int strcmp(const char *str1, const char *str2){assert(str1 != NULL);assert(str2 != NULL);while ((*str1 == *str2) && (*str1 != '\0')){str1++;str2++;}return *str1 - *str2;}
strlen() 字符串求长度
int my_strlen(const char*str){int count = 0;assert(str != NULL);while (*str++ != '\0'){count++;}return count;}
strncpy() 复制指定长度字符串
char* my_strncpy(char* dest, const char* src, int len){assert(dest);assert(src);char* temp = dest;int i = 0;while (i++ < len && (*temp++ = *src++) != '\0'){}return dest;}
strncmp() 比较指定长度字符串
int my_strncmp(const char *s1, const char *s2, int n){assert(s1);assert(s2);while (*s1 != '\0'&&*s2 != '\0'&&n){if (*s1 - *s2>0)return 1;if (*s1 - *s2<0)return -1;s1++;s2++;n--;}if (*s1 == '\0'&&*s2 != '\0')return -1;if (*s2 == '\0'&&*s1 != '\0')return 1;return 0; }
strncat() 添加指定长度字符串
char *my_strncat(char *dest, const char *str, int n){assert(dest);assert(str);char *cp = dest;while (*++cp != '\0'){}while (--n && (*cp++ = *str++) != '\0'){}return dest;}
阅读全文
1 0
- 字符串操作函数实现strcpy() strcmp()...
- strlen, strcpy, strcat, strcmp, memset... (字符串操作函数的实现)
- C++常见字符串操作函数的实现(strcpy/strcat/strcmp/strlen/strchr/strstr/strpbrk/strrev等)
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
- C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文
- 字符串操作函数Strcat、Strcpy、Strcmp、Strlen原型
- 语言字符串操作函数 - strcpy、strcmp、strcat、反转
- 字符串函数strcat, strcpy, strcmp, strlen实现模型
- 模拟实现strlen、strcpy、strcmp、strncmp等字符串函数
- 模拟实现字符串操作函数(strcpy,strstr,strcat,strcmp,strlen)与内存操作函数(memcpy,memmove)
- strcat , strcpy , strcmp 函数实现
- C字符串函数strcmp\strcpy\strcat\memcpy
- 自定义字符串函数:strlen,strcat,strcpy,strcmp
- 自定义字符串函数:strlen,strcat,strcpy,strcmp
- 字符串相关函数、strcat,strcpy,strcmp
- 函数strcpy、strcat和strcmp实现源码
- 如何理解Python装饰器?
- CSS3动画实现登录界面
- PHP内核探索之变量(4)- 数组操作
- 服务器 'FILE' 上的 MSDTC 不可用
- Mybatis 批量查询 Map 嵌套 List
- 字符串操作函数实现strcpy() strcmp()...
- 线程绑定CPU核-sched_setaffinity——003
- 分数化小数
- jQuery 的attr()与css()的区别
- svn基本操作
- break和continue的区别
- UE4上传图片和PHP交互
- Linux环境下RPM交叉编译找不到libz.so.1的动态库
- linux IIC详解