void StringPuzzles::revertWordsInString(char * str, int size) { revertString(str, size); int left = 0; int right = 0; while(left < size) { while(left < size && str[left] == ' ') left++; right = left; while(right < size && str[right] != ' ') right++; int length = right - left; revertString(str, length, left); left = right; } }
int main() { char s[] = "SMO is a very successful product in Brion"; printf("The original string is :\n%s\n", s); revertString(s); printf("After reverting in place, the string is :\n%s\n", s); return 0; }
void toStr(int value, char* result) { char* pos = result; int isNegative = value < 0; if ( isNegative ) value *= -1; while ( value > 0 ) { int calc = value % 10; *pos++ = '0' + (value % 10); value /= 10; } if ( isNegative ) *pos++ = '-'; revertString(result, pos-1); *pos = '\0'; }
void StringPuzzles::revertString(char * str) { revertString(str, std::strlen(str)); } // end method