当前位置:网站首页>Rewrite four functions such as StrCmp in C language
Rewrite four functions such as StrCmp in C language
2022-04-23 18:03:00 【OceanKeeper1215】
#include <stdio.h>
#include <string.h>
#include <assert.h>
size_t str_len(const char* str)
{
// if(NULL == str) return -1;
assert(NULL != str);
const char* tmp = str;
while(*tmp) tmp++;
return tmp - str;
}
char* str_cpy(char* dest,const char* src)
{
assert(NULL != dest && NULL != src);
char* tmp = dest;
while(*tmp++ = *src++);
return dest;
}
char* str_cat(char* dest,const char* src)
{
assert(NULL != dest && NULL != src);
char* tmp = dest;
while(*tmp) tmp++;
while(*tmp++ = *src++);
return dest;
}
int str_cmp(const char* s1,const char* s2)
{
assert(NULL != s1 && NULL != s2);
while(*s1 && *s1 == *s2) s1++,s2++;
// return *s1-*s2;
if(*s1 > *s2)
return 1;
else if(*s1 < *s2)
return -1;
else
return 0;
}
int main(int argc,const char* argv[])
{
char str[256] = "hehe";
char* str1 = NULL;
// strcpy(str,str1);
printf("str_len: %d\n",str_len(str1));
printf("str_cpy: %s\n",str_cpy(str,"abc"));
printf("str_cat: %s\n",str_cat(str,"qqq"));
printf("str_cmp: %d\n",str_cmp("abb","abb"));
}
版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545105048.html
边栏推荐
- Implementation of object detection case based on SSD
- Crawling mobile game website game details and comments (MQ + multithreading)
- undefined reference to `Nabo::NearestNeighbourSearch
- 纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
- Implementation of k8s redis one master multi slave dynamic capacity expansion
- Queue solving Joseph problem
- C language array processing batch data
- Build openstack platform
- Operators in C language
- Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
猜你喜欢

A few lines of code teach you to crawl lol skin pictures

MySQL auto start settings start with systemctl start mysqld

2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition

.105Location
![C1 notes [task training chapter I]](/img/2b/94a700da6858a96faf408d167e75bb.png)
C1 notes [task training chapter I]

开源按键组件Multi_Button的使用,含测试工程

2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination

GDAL + ogr learning

Qtablewidget usage explanation

Auto.js 自定义对话框
随机推荐
Install pyshp Library
极致体验,揭晓抖音背后的音视频技术
Cloud native Virtualization: building edge computing instances based on kubevirt
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Re expression régulière
Amount input box, used for recharge and withdrawal
Gaode map search, drag and drop query address
Climbing watermelon video URL
xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
20222 return to the workplace
Pyppeter crawler
Docker 安裝 Redis
C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
C#的随机数生成
Operation of 2022 mobile crane driver national question bank simulation examination platform
Summary of floating point double precision, single precision and half precision knowledge
Logic regression principle and code implementation
MySQL auto start settings start with systemctl start mysqld
Dock installation redis
ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes