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

推荐订阅源

人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
S
SegmentFault 最新的问题
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
U
Unit 42
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - Franky
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research

Victrid's Personal Site

斯普拉遁3打工模式联机网络过程分析 DHCP无类型静态路由──一个摆设 配置透明代理,实现无感上网 Generating Unlimited Grammar: A Messenger Perspective LaTeX插入其他PDF中的矢量图 光速不变原理和迈克尔孙──莫雷实验 交大葡萄演义 调试微信内置浏览器 欧悌甫戎篇 苏格拉底的申辩篇 LCA 最近公共祖先 弥罗斯人的辩论 埃斯库罗斯作品:波斯人、阿伽门农 电路理论资料 Coronavirus: A Humanitarian Crisis 雨夜 linux配置SSR 二叉堆的实现 懒政 Placement New Flipped: A Love Story 我宁可呆在这样的疯人院里 谈新发本地病例 勇敢与智慧 Powerful but Limited Drafted VLC Libva Error Troubleshooting Ring-Fit新上手 政治艺术化与艺术政治化 动态规划——从分割等和子集入手
C-Style String Operation
Victrid · 2019-10-29 · via Victrid's Personal Site

Here introduces C-style 'string' (mostly char[]) operation.

It's important that with classes and many more useful and Memory Safe functions, string shall not be processed with these functions.


  1. strcpy(dst,source),return dstcopy source to destination, returning the address of destination. be cautious that it can cause memory leak. example:

    char b[5]={0};

    char a[]="abcdefghijklmn";

    cout << (int)strcpy(b,a);you'll get an address.

    cout << ' ';

    for(int i = 0;i<=15;i++)cout<<b[i];

    returns:

    1
    2
    6422204          abcdefghijklmn#
    #:memory leak^
  2. strncpy(dst,src,n),return dstcopy n characters at most from source to destination. returning the address of destination. (better than strcpy to avoid memory leak.)

  3. strcat(dst,src),return dstadd src to the end of dst. Returning the address of dst.

  4. strncat(dst,src,n),return dst analogise with 2.

  5. strlen(s),return intlength of a string(to the \0, not the size of a list).

  6. strcmp(s1,s2),return intreturn (s1-s2).

  7. strncmp(s1,s2,n),return int,anal. with 2.

  8. strchr(s,ch),return addrreturn the address of the first ch in s.

    example:

    char a[]="abcdefghijklmn";

    cout<<strchr(a,'f'); returns: 6422278

    example:

    char a[]="abcdefghijklmn";

    cout<<(int)strchr(a,'q'); returns: 0

  9. strrchr(s,ch),return addrreturn the address of the last ch in s.

  10. strstr(s1,s2),return addranal with 7,but finding s2.

Author: Victrid

Permanent Link: https://victrid.dev/2019/c-style-string-operation/

License: Copyright (c) 2025 victrid Terms of Use

Ads by Google

Read our privacy policy on how these personalized advertisements are delivered to you.

For your reading experience, we provide full-text RSS feeds. Although math formulas cannot be displayed well, the interface can be adjusted as you like and there are no ads.