Question: Write a program that accepts a C-string (or C++ string) input from the user and reverses the contents of the string Your program should work

 Write a program that accepts a C-string (or C++ string) input

Write a program that accepts a C-string (or C++ string) input from the user and reverses the contents of the string Your program should work by using two pointers. The "head" pointer should be set to the address of the first character in the string, and the "tail" pointer should be set to the address of the last character in the string (that is, the character before the terminating null) The program should swap the characters referenced by these points, increment "head" to point to the next character, decrement "tail" to point to the second-to-last character, and so on, until all characters have been swapped and the entire string reversed. Be sure to account for even and odd number of characters in the string #include #include #include using namespace std; int main() {char *pHead; char *pTail; pHead = pTail = str; cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!