int main() { string phrase; string stripped; string reversed; string reverseStripped; phrase = "Hello World ? ? !!..."; stripped = StripClass(phrase, ispunct); reversed = Reverse(phrase); reverseStripped = Reverse(stripped); PrintLabeled(phrase,"Phrase"); PrintLabeled(stripped,"Stripped"); PrintLabeled(reversed,"Reversed"); PrintLabeled(reverseStripped,"Reverse Stripped"); return 0; }
int main() { string phrase; string stripped; string reversed; string reverseStripped; phrase = "Hello World ? ? !!..."; stripped = bah(phrase, ispunct); reversed = hab(phrase); reverseStripped = hab(stripped); PL(phrase,"Phrase"); PL(stripped,"Stripped"); PL(reversed,"Reversed"); PL(reverseStripped,"Reverse Stripped"); return 0; }
string Reverse(string s) { string rv; size_t i; for(i=0;i<s.size();i++) { rv = s[i] + rv; } return rv; }
// this function will reverse a string. Isn't the name clever // I will just change variable names in this one string hab(string x) { string r; size_t j; for(j=0;j<x.size();j++) { r = x[j] + r; } return r; }
string StripClass(string phrase, int(*TestFunc)(int)) { size_t i; string rv; for(i=0;i<phrase.size();i++) { if (! TestFunc(phrase[i])) { rv += phrase[i]; } } return rv; }
// changing variable names, spacing, indentation // adding comments. // this should confuse it. string bah(string s, int(*x)(int)) { // a loop control variable, this will be used to look at the string size_t LCV; // I want to send this back. string back; // just loop over th string for(LCV = 0; LCV < s.size() ; LCV++) { if (! x ( s [ LCV ] ) ) // does the passed in function recognise the value { back += s[LCV]; // if not, add the letter back into the string } } return back; // send it back }