Exemple #1
0
int main()
{
	char string[] = "reverseme";
	printf("Original string: %s\n", string);

	reverseStringInPlace(string);

	printf("Reversed string: %s\n", string);

}
void testReverseStringInPlace() {
    cout << endl;
    cout << "Test reverseStringInPlace():" << endl;
    cout << "============================" << endl;

    const char* testStrings[] = {
        "",
        "Hello, world!",
        "!dlrow ,olleH",
        "abcdefghijklmnopqrstuvwxyz"
    };

    for (auto& s : testStrings) {
        char* sCopy = new char[strlen(s) + 1];
        strcpy(sCopy, s);
        reverseStringInPlace(sCopy);
        cout << "reverseStringInPlace(\"" << s
             << "\") = \"" << sCopy << "\"" << endl;
        delete[] sCopy;
    }
}