当前位置:网站首页>C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
2022-04-23 05: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://blog.csdn.net/tilblackout/article/details/124332275
边栏推荐
- [UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
- C语言进阶要点笔记2
- Latex configuration and use
- Qt 给应用程序加图标
- 如何读文献
- 【UDS统一诊断服务】二、网络层协议(2)— 数据传输规则(单帧与多帧)
- 拷贝构造函数
- [UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
- [ThreadX] ThreadX source code reading plan (I)
- 生成验证码
猜你喜欢
【UDS统一诊断服务】二、网络层协议(2)— 数据传输规则(单帧与多帧)
Installation of GCC, G + +, GDB
[ThreadX] h743zi + lan8720 + ThreadX + netx duo transplantation
【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
C语言循环结构程序
【UDS统一诊断服务】四、诊断典型服务(3)— 读故障信息功能单元(存储数据传输功能单元)
ArcGIS license错误-15解决方法
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
jenkspy包安装
Completely clean up MySQL win
随机推荐
[learn] HF net training
Matlab标定板角点检测原理
vs中的多字节与unicode
[UDS unified diagnostic service] III. application layer protocol (1)
【无标题】
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
基于VGG对五种类别图片的迁移学习
MySQL groups are sorted by a field, and the first value is taken
圆整 round 的一点点小细节
GDB debugger installation and use
[ThreadX] ThreadX source code reading plan (I)
PM2 deploy nuxt related commands
C语言的浪漫
C语言进阶要点笔记5
Vscode custom comments
安装pyshp库
Installation of GCC, G + +, GDB
Figure guessing game
产生随机数
copy constructor