29. Write a complete C++ program that asks the user to enter text into a charact
ID: 3767618 • Letter: 2
Question
29. Write a complete C++ program that asks the user to enter text into a character array (a C-string). Send the text to a function called ReverseIt. This function will fill a second C-string so that the original string is reversed (as described in Problem 26). Limit the size of the C-strings to fifty characters. The last charac- ter in the original string (before the null) should be the first character of the second string. Write both C-strings from main. Incorporate a loop so that the user can continue to enter strings until he chooses to stopExplanation / Answer
#include <iostream>
#include <string>
using namespace std;
void ReverseIt(char *saying,char *reverse)
{
int len = (int)strlen(saying);
int j = len-1;
int i = 0;
while(j>=0)
{
reverse[i] = saying[j];
i++;
j--;
}
reverse[i] = '';
}
int main() {
char saying[50],revsaying[50];
cout << "Input a saying : ";
cin.getline(saying,sizeof(saying));
cout << saying << endl;
ReverseIt(saying,revsaying);
cout << revsaying;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.