当前位置:网站首页>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
边栏推荐
- Use of list - addition, deletion, modification and query
- Sword finger offer 22 The penultimate node in the linked list - speed pointer
- MySQL进阶之索引【分类,性能分析,使用,设计原则】
- 双闭环直流调速系统matlab/simulink仿真
- SystemVerilog (VI) - variable
- 440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
- 双指针进阶--leetcode题目--盛最多水的容器
- 20222 return to the workplace
- 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
- EasymodbusTCP之clientexample解析
猜你喜欢
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
MySQL installation
【Appium】通过设计关键字驱动文件来编写脚本
Applet learning notes (I)
Qt error: /usr/bin/ld: cannot find -lGL: No such file or directory
958. 二叉树的完全性检验
土地覆盖/利用数据产品下载
48. 旋转图像
On the method of outputting the complete name of typeID from GCC
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
随机推荐
Cross domain settings of Chrome browser -- including new and old versions
Open source key component multi_ Button use, including test engineering
Commonly used functions -- spineros:: and spineros::)
386. 字典序排数(中等)-迭代-全排列
470. 用 Rand7() 实现 Rand10()
PC uses wireless network card to connect to mobile phone hotspot. Why can't you surf the Internet
Compare the performance of query based on the number of paging data that meet the query conditions
Oil monkey website address
Operation of 2022 mobile crane driver national question bank simulation examination platform
Matlab / Simulink simulation of double closed loop DC speed regulation system
双指针进阶--leetcode题目--盛最多水的容器
Kubernetes service discovery monitoring endpoints
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
Open futures, open an account, cloud security or trust the software of futures companies?
Kubernetes 服务发现 监控Endpoints
209. Minimum length subarray - sliding window
Add drag and drop function to El dialog
ros常用的函数——ros::ok(),ros::Rate,ros::spin()和ros::spinOnce()
JVM class loading mechanism
Construction of functions in C language programming