当前位置:网站首页>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
边栏推荐
- Process management command
- Using files to save data (C language)
- Fashion classification case based on keras
- Halo open source project learning (II): entity classes and data tables
- MySQL_ 01_ Simple data retrieval
- Svn simple operation command
- Encapsulate a timestamp to date method on string prototype
- 开源按键组件Multi_Button的使用,含测试工程
- Basic usage of crawler requests
- Remember using Ali Font Icon Library for the first time
猜你喜欢

Re expression régulière

极致体验,揭晓抖音背后的音视频技术

Gaode map search, drag and drop query address

Re regular expression

The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time

解决允许在postman中写入注释请求接口方法
![C1 notes [task training part 2]](/img/10/48f7490a6c097f2b178ae948cb2c91.png)
C1 notes [task training part 2]
![Yolov4 pruning [with code]](/img/09/ea4376d52edb7e419ace2cb1e0356b.gif)
Yolov4 pruning [with code]

Cloud native Virtualization: building edge computing instances based on kubevirt

2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
随机推荐
.104History
Solving the problem of displaying too many unique values in ArcGIS partition statistics failed
C language loop structure program
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
Crawling mobile game website game details and comments (MQ + multithreading)
Crawl the product data of cicada mother data platform
Auto.js 自定义对话框
Pyppeter crawler
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Implementation of object detection case based on SSD
Using files to save data (C language)
Summary of common server error codes
Install pyshp Library
MySQL_ 01_ Simple data retrieval
Timestamp to formatted date
Encapsulate a timestamp to date method on string prototype
Build openstack platform
Nanotechnology + AI enabled proteomics | Luomi life technology completed nearly ten million US dollars of financing
Format problems encountered in word typesetting