#include <iostream>using namespace STD;//Implement a function to find the length of a string. intMy_length (Const Char*s) {if(*s = =' + ')return 0;Else return 1+my_length (S +1);}intMain () {Char*s ="123456";cout<< My_length (s) << Endl;return 0;}#include <iostream>#include <assert.h>using namespace STD;//implements the length of a string to be evaluated. intMy_length (Const Char*s) {if(s = = NULL)return 0;intCount =0; while(S[++count]! =' + ');returnCount;}intMain () {Char*s ="";cout<< My_length (s) << Endl;return 0;}#include <iostream>#include <string.h>#include <assert.h>using namespace STD;Char* MY_STRCPY (Char*dist,Const Char*scour) {assert (scour!=null);Char*p = dist; while(*dist++ = *scour++);returnP;}intMain () {Char*S1 ="123";Char*S2 =New Char[strlen(S1)];cout<< my_strcpy (S2, S1) << Endl;return 0;}#include <iostream>#include <assert.h>using namespace STD;//Implement library function strcat. Char* MY_STRCAT (Char*dist,Char Const*scour) {assert (Dist!=null | | scour!=null);if(*scour = =' + ')returnDistChar*p = dist; while(*dist! =' + ') dist++; while(*dist++ = *scour++);returnP;}intMain () {Char*S1 =New Char[Ten];strcpy(S1,"123");cout<< My_strcat (S1,"456") <<endl;return 0;}#include <iostream>#include <assert.h>#include <string.h>using namespace STD;//write a program to reverse the string. Char* My_invert (Char*s) {assert (s! = NULL);Char*head = s;Char*last = s+strlen(s)-1;CharTemp while(Head < last) {temp = *head; *head = *last; *last = temp; head++; last--; }returns;}intMain () {Char*s =New Char[Ten];strcpy(S,"12345");cout<< My_invert (s) << Endl;return 0;}#include <iostream>#include <assert.h>using namespace STD;//simulation implements the STRCHR function, function: Finds the first occurrence of a character in a string and returns null if it does not appear. intMy_strchar (Const Char* Dist,CharCH) {assert (dist!=null);intCount =0; while(*dist! =' + '&& *dist!=ch) {count++; dist++; }if(*dist = =' + ')return 0;returncount+1;}intMain () {cout<< My_strchar ("1234",' 1 ') << Endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C + + string manipulation collection