1. Brief Introduction
Removes all characters that have occurred in another string from one string. It is basically relatively simple. It mainly refers to placing the characters to be saved in the proper position, releasing the characters to be deleted, and processing the characters '\ 0.
2. Code
# Include <iostream>
Using namespace STD;
Bool find (const char * cs, const char ch ){
Assert (CS! = 0 );
While ('\ 0 '! = * Cs & Ch! = * Cs)
CS ++;
If ('\ 0' = * cs)
Return false;
Else
Return true;
}
Void delete_str (char * STR, const char * cs ){
Assert (STR! = 0 & CS! = 0 );
Char * result = str;
Int gap, len; gap = len = 0;
While (* str! = '\ 0 '){
If (find (cs, * str) {// discard this character
Gap ++; // number of characters deleted
}
Else {// save this character
Len ++; // number of reserved characters
* (Str-gap) = * str;
}
Str ++;
}
* (Result + len) = '\ 0'; //' \ 0' for processing
For (int I = 0; I <gap; I ++) // release the memory
Delete (result + Len + I + 1 );
}
Int main (){
Char STR [100] = {'h', 'E', 'l', 'l', 'O', ',', 'w', 'O ', 'R', 'l', 'D ','. '};
Char CS [5] = "Lo ";
Cout <STR <Endl;
Cout <CS <Endl;
Delete_str (STR, CS );
Cout <STR <Endl;
System ("pause ");
Return 0 ;}
3. Remarks
It is difficult to test basic C ++ programming.