惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
AI
AI
B
Blog RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threatpost
I
Intezer
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Webroot Blog
Webroot Blog
Recorded Future
Recorded Future
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
Simon Willison's Weblog
Simon Willison's Weblog
MyScale Blog
MyScale Blog
Project Zero
Project Zero
L
LangChain Blog
B
Blog
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
F
Fortinet All Blogs
美团技术团队
Engineering at Meta
Engineering at Meta
Cisco Talos Blog
Cisco Talos Blog
D
Docker
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
S
Security Affairs
Attack and Defense Labs
Attack and Defense Labs
N
News | PayPal Newsroom
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
V2EX - 技术
V2EX - 技术
TaoSecurity Blog
TaoSecurity Blog
博客园 - Franky
P
Proofpoint News Feed
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
The Hacker News
The Hacker News
G
GRAHAM CLULEY

博客园 - ZefengYao

Markdown 入门与 Word 使用指南 关于崩溃报告的日志以及dump文件 hdu 6223 Infinite Fraction Path 2017南宁现场赛E The Champion ACM-ICPC 2018 南京赛区网络预赛 Sum 各种类型排序的实现及比较 随机洗牌算法Knuth Shuffle和错排公式 两个栈实现队列 面试杂题 面试题——栈的压入、弹出顺序 C++ 智能指针的简单实现 openGL初学函数解释汇总 foj Problem 2107 Hua Rong Dao foj Problem 2282 Wand UVA-1400 Ray, Pass me the dishes! 《挑战程序设计竞赛》 利用后缀数组求最长回文串 Uva 11174 Stand in a Line UVA 11375 Matches poj 3729 Facer’s string
c语言几个字符串处理函数的简单实现
ZefengYao · 2018-08-28 · via 博客园 - ZefengYao

直接贴代码:

char* strcpy(char *a,char*b){//把字符串b全部拷贝到a中
    assert(a != nullptr&&b != nullptr);
    char *p = a;
    while ((*p++ = *b++) != '0');
    return p;
}
char *strncpy(char *a,char *b,int n) {//把字符串b的前n位拷贝到a中
    assert(a != nullptr&&b != nullptr);
    char *p = a;
    while (n--) {
        if ((*p++ = *b++) == '\0')break;
    }
    return p;
}
char *strcat(char *a,char *b) {//把b拼接于a后
    assert(a != nullptr&&b != nullptr);
    char *p = a;
    while (*p != '\0')p++;
    while ((*p++ = *b++) != '\0');
    return p;
}
int strcmp(char*a,char *b) {//比较字符串
    assert(a != nullptr&&b != nullptr);
    while (*a&&*b&&*a==*b) {
        a++, b++;
    }
    if (*a > *b)return 1;
    else if (*a < *b)return -1;
    else return 0;
}
int strlen(char *a) {
    assert(a != nullptr);
    int len = 0;
    while (*a != '\0') {
        a++,len++;
    }
    return len;
}