![](/style/images/good.png)
![](/style/images/bad.png)
C-Style String Operation
source link: https://victrid.dev/2019/c-style-string-operation/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C-Style String Operation
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.
-
strcpy(dst,source),return dst
copy 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:
6422204 abcdefghijklmn#
#:memory leak^ -
strncpy(dst,src,n),return dst
copy n characters at most from source to destination. returning the address of destination. (better than strcpy to avoid memory leak.) -
strcat(dst,src),return dst
add src to the end of dst. Returning the address of dst. -
strncat(dst,src,n),return dst
analogise with 2. -
strlen(s),return int
length of a string(to the \0, not the size of a list). -
strcmp(s1,s2),return int
return (s1-s2). -
strncmp(s1,s2,n),return int
,anal. with 2. -
strchr(s,ch),return addr
return 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
-
strrchr(s,ch),return addr
return the address of the last ch in s. -
strstr(s1,s2),return addr
anal with 7,but finding s2.
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.
Recommend
-
103
Smartrep smartrep is a sequential command interface library. It enables the omittance of typing prefix keys. (e.g., C-c C-n C-n C-n … instead of C-c C-n C-c C-n C-c C-n …) Contents Usage sm...
-
50
SimplePHPEasyPlus - A simple, pragmatic numeric operation api written in PHP. It does addition.
-
124
I am getting this error message from GitKraken whenever I try to clone/fetch/push/push to any of my Github repositories: failed to get server certificate: The handle is in the wrong state for the
-
83
Practical Multi-Word Compare-and-Swap Operation This paper is about how to implement an efficient and practical multi-word compare-and-swap operation. Multi-word here means discontiguous words, not just a 16-b...
-
55
README.md Click me switch to English version Tars Tars这个名字取自于电影"星际穿越"中的机器人,它是基于名字服务使用Tars协议的高性能RPC...
-
50
Update note : James Goodwill updated this tutorial for Xcode 10 and Swift 4.2. Soheil Azarpour wrote the original post and Richard Turton completed a previous update.
-
5
Preamble¶ :dep darn =...
-
5
How can I produce a C-style array from a Windows Runtime asynchronous operation? Raymond December 3rd, 2021 C-style arr...
-
4
...
-
4
Performance Gains in Ruby 3.3- String.dup vs. String#+ Jan 23, 2024 •
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK