1.模拟实现strncpy 2.模拟实现strncat 3.模拟实现strncmp
来源:互联网 发布:路由器怎么网络慢 编辑:程序博客网 时间:2024/05/16 00:51
在C语言string这个库中的strcpy,strcat,strcmp这三个函数是通过传递数组的内容来限制它们的,这样做并不是一个好方法,所以新增了strncpy,strncat,strncmp这三个函数,用传参的方式现实字符串的改变长度,模拟实现如下:
strncpy
char* my_strncpy(char*dest, const char*src, int n) { assert(dest); assert(src); char*p = dest; while (n--) { *p++ = *src++; } *p = 0; return dest; }
strncat
char* my_strncat(char*dest, const char*src, int n) { assert(dest); assert(src); char*p = dest; while (*p) { p++; } while (n--) { *p++ = *src++; } *p = 0; return dest; }
strncmp
int my_strncmp(const char*str1, const char*str2, int n) { assert(str1); assert(str2); while (n--) { if (*str1 == *str2) { str1++; str2++; } else { if ((*str1-*str2)<0) return -1; else return 1; } } return 0; }
阅读全文
0 0
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 模拟实现strncpy,strncat,strncmp
- 1.模拟实现strncpy 2.模拟实现strncat 3.模拟实现strncmp
- 模拟实现strncpy ,模拟实现strncat ,模拟实现strncmp
- 模拟实现C库函数strncpy、strncat、strncmp
- 模拟实现C语言strncpy.strncat.strncmp函数
- 【C语言】模拟实现strncpy、strncat、strncmp函数
- 模拟实现strcpy,strncpy,strcat,strncat,strcmp,strncmp,memcpy,memmove
- 【C语言】模拟实现strncpy strncat strncmp strchr strrchr函数
- 模拟实现 strncpy strncat strncmp strchr strrchr 函数
- C语言~模拟实现strncpy、strncat、strncmp函数
- 模拟实现C库函数:strncpy、strncat和strncmp
- 模拟实现strcpy 模拟实现strncpy 模拟实现strcat 模拟实现strncat 模拟实现strcmp 模拟实现strncmp 模拟实现memcpy 模拟实现memmove
- [C语言]模拟实现strcpy/strncpy/strcat/strncat/strcmp/strncmp/strstr
- 模拟实现strcmp,strncmp,strstr,strcat,strncat,strcpy,strncpy,strlen ,memcpy,memmove等函数
- 模拟实现长度受限制的字符串函数(strncpy、strncat、strncmp)
- Winform怎么复制窗体/C#窗体复用怎么做
- 对称加密:AES
- 在win2008 iis7下如何设置Discuz伪静态教程
- Android 沉浸式状态栏的简单实现
- C语言调用http接口
- 1.模拟实现strncpy 2.模拟实现strncat 3.模拟实现strncmp
- 多态
- 形参和实参的区别
- ubuntu终端显示内容颜色问题及解决办法
- android 对图片尺寸压缩的工具类,简单明了
- 【转】Spring Boot干货系列:(二)配置文件解析
- 跨域方法的整理
- 两年软件测试工程师告诉你:他是怎么做测试用例的
- go语言学习笔记(4) 变量