diff --git a/c++/Chapter 1/Question1_2/Question1_2.cpp b/c++/Chapter 1/Question1_2/Question1_2.cpp index bd2941ef..6a70d529 100644 --- a/c++/Chapter 1/Question1_2/Question1_2.cpp +++ b/c++/Chapter 1/Question1_2/Question1_2.cpp @@ -6,17 +6,10 @@ using std::endl; void Question1_2::reverse(char* str) { - char *ptrEnd = str; - char temp; - if (str) { - while (*ptrEnd) - { - ptrEnd++; - } - ptrEnd--; - + char *ptrEnd = &str[strlen(str) - 1]; + char temp; while (str < ptrEnd) { temp = *str; @@ -38,4 +31,4 @@ int Question1_2::run() } return 0; -} \ No newline at end of file +}