当前位置:网站首页>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] III. application layer protocol (1)](/img/e7/813e29a30e08eb92ccc836743be9aa.png)
[UDS unified diagnostic service] III. application layer protocol (1)

for()循环参数调用顺序

在visual stdio中运行qt程序

Robocode教程8——AdvancedRobot

jenkspy包安装

函数的调用过程

File viewing commands and user management commands

Detailed arrangement of knowledge points of University probability theory and mathematical statistics
随机推荐
GDB debugger installation and use
Swagger2 generates API documents
爬取彩票数据
大学概率论与数理统计知识点详细整理
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
C语言进阶要点笔记5
C#中?的这种形式
PHP junior programmers, take orders and earn extra money
Rust:单元测试(cargo test )的时候显示 println 的输出信息
类和对象的初始化(构造函数与析构函数)
grub boot. S code analysis
搭建openstack平台
【UDS统一诊断服务】四、诊断典型服务(2)— 数据传输功能单元
四元数乘法
【UDS统一诊断服务】三、应用层协议(1)
猜數字遊戲
【UDS统一诊断服务】一、诊断概述(2)— 主要诊断协议(K线和CAN)
文件查看命令和用户管理命令
【UDS统一诊断服务】四、诊断典型服务(3)— 读故障信息功能单元(存储数据传输功能单元)
[ThreadX] ThreadX source code reading plan (I)