当前位置:网站首页>C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
2022-04-23 17:50:00 【tilblackout】
1、memcpy
void *memcpy(void *dst, const void *src, unsigned int len)
{
void * ret = dst;
while (len-- > 0) *((char *)dst)++ = *((char *)src)++;
return ret;
}
2、memset
void * memset(void * s,char c,size_t count)
{
char *xs = (char *) s;
while (count--)
*xs++ = c;
return s;
}
3、strcpy
char * strcpy(char * dest,const char *src)
{
char *tmp = dest;
while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
4、strncpy
char * strncpy(char * dest,const char *src,size_t count)
{
char *tmp = dest;
while (count-- && (*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
5、strcmp
int strcmp(const char * cs,const char * ct)
{
register signed char __res;
while (1) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
}
return __res;
}
6、strncmp
int strncmp(const char * cs,const char * ct,size_t count)
{
register signed char __res = 0;
while (count) {
if ((__res = *cs - *ct++) != 0 || !*cs++)
break;
count--;
}
return __res;
}
7、strlen
size_t strlen(const char * s)
{
const char *sc;
for (sc = s; *sc != '\0'; ++sc)
/* nothing */;
return sc - s;
}
版权声明
本文为[tilblackout]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549282312.html
边栏推荐
- Halo 开源项目学习(二):实体类与数据表
- 386. Dictionary order (medium) - iteration - full arrangement
- Construction of functions in C language programming
- 双指针进阶--leetcode题目--盛最多水的容器
- In embedded system, must the program code in flash be moved to ram to run?
- Detailed deployment of flask project
- Submit local warehouse and synchronize code cloud warehouse
- 239. Maximum value of sliding window (difficult) - one-way queue, large top heap - byte skipping high frequency problem
- [二叉数] 二叉树的最大深度+N叉树的最大深度
- Type judgment in [untitled] JS
猜你喜欢
Error in created hook: "referenceerror:" promise "undefined“
102. Sequence traversal of binary tree
QT modification UI does not take effect
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
48. 旋转图像
MySQL installation
关于gcc输出typeid完整名的方法
MySQL进阶学习之SQL优化【插入,主键,排序,分组,分页,计数】
Learning record of uni app dark horse yougou project (Part 2)
Tell the truth of TS
随机推荐
How to manually implement the mechanism of triggering garbage collection in node
SystemVerilog(六)-变量
剑指 Offer 22. 链表中倒数第k个节点-快慢指针
MySQL advanced index [classification, performance analysis, use, design principles]
嵌入式系统中,FLASH中的程序代码必须搬到RAM中运行吗?
Where is the configuration file of tidb server?
587. 安装栅栏 / 剑指 Offer II 014. 字符串中的变位词
土地覆盖/利用数据产品下载
Compare the performance of query based on the number of paging data that meet the query conditions
MySQL进阶之索引【分类,性能分析,使用,设计原则】
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
SystemVerilog (VI) - variable
958. Complete binary tree test
ros常用的函数——ros::ok(),ros::Rate,ros::spin()和ros::spinOnce()
394. String decoding - auxiliary stack
48. 旋转图像
2021 Great Wall Cup WP
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
48. Rotate image
Chrome浏览器的跨域设置----包含新老版本两种设置