In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
How to implement several common string functions, I believe that many inexperienced people are at a loss about this. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Implement several common string functions and practice writing code. Always thank the code so that you don't forget how to write it.
Character comparison function
String assignment function
Find the length of the string
The inversion of the string
String comparison
String concatenation
/ / string.cpp: Defines the entry point for the console application.//#include "stdafx.h" # include # include "string.h" / / character exchange function void charswap (char& ch2, char& ch3) {char ch = ch2; ch2 = ch3; ch3 = ch;} / / find the string length int stringlength (const char* sourstr) {const char* pstr = sourstr; int length = 0 While (* pstr++! ='\ 0') {length++;} return length;} / / string that inverted char* stringconvert (char* sourstr) {int length = stringlength (sourstr); int loopnumber = length / 2; int index = 0 While (index < loopnumber) {charswap (* (sourstr + index), * (sourstr + length-index-1)); index++;} return sourstr;} / / string copy char* stringcopy (char* deststr, const char* sourstr) {const char* pstr = sourstr; int index = 0 While (* pstr! ='\ 0') {* (deststr + index) = * pstr++; index++;} * (deststr + index) ='\ 0strings concatenate char* stringcontact (char* deststr, const char* sourstr) {const char* pstr = sourstr; int length = stringlength (deststr); int index = 0 While (* pstr! ='\ 0') {* (deststr + length + index) = * pstr++; index++;} * (deststr + length + index) ='\ 0strings; return deststr;} / / string comparison function int stringcompare (const char* deststr, const char* sourstr) {const char* pdest = deststr; const char* psour = sourstr While (* pdest = = * psour & & * pdest! ='\ 0') {pdest++; psour++;} return * pdest-* psour;} int main (int argc, char* argv []) {char buff1 [100]; char buff2 [100]; stringcopy (buff1, "reqre12345"); stringcopy (buff2, "reqre1") Printf ("% d\ n", stringcompare (buff1, buff2)); getchar (); return 0;} after reading the above, do you know how to implement several common string functions? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.