当前位置:网站首页>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
边栏推荐
- Basemap库绘制地图
- 基于SSD的物体检测案例实现
- [UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
- 爬取小米有品app商品数据
- copy constructor
- PM2 deploy nuxt related commands
- [untitled]
- [UDS unified diagnostic service] III. application layer protocol (1)
- C语言实用小技巧合集(持续更新)
- vs中能编译通过,但是会有红色下划线提示未定义标示符问题
猜你喜欢
【UDS统一诊断服务】四、诊断典型服务(3)— 读故障信息功能单元(存储数据传输功能单元)
jenkspy包安装
Qt 给应用程序加图标
Basemap库绘制地图
[UDS unified diagnostic service] III. application layer protocol (1)
Introduction to nonparametric camera distortion model
[UDS unified diagnosis service] i. diagnosis overview (2) - main diagnosis protocols (K-line and can)
[ThreadX] h743 + ThreadX + Filex migration record
【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (2)
卷积神经网络实现CIFAR100数据集分类
随机推荐
Eigen 库常用基本用法 备忘
C语言输入和输出(printf和scanf函数、putchar和getchar函数)
Friend function, friend class, class template
TP download folder, compress folder and download
[UDS unified diagnostic service] III. application layer protocol (1)
C语言实现2048小游戏方向合并逻辑
猜数字游戏
爬取彩票数据
Swagger2 generates API documents
LaTeX配置与使用
vs中能编译通过,但是会有红色下划线提示未定义标示符问题
如何读文献
[opencv] use filestorage to read and write eigenvectors
Detailed arrangement of knowledge points of University probability theory and mathematical statistics
基于Keras的时装分类案例
搭建openstack平台
[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)
jenkspy包安装
[untitled]
MySQL groups are sorted by a field, and the first value is taken