Write a complete C++ program that asks the user to enter text into a character a
ID: 3766781 • Letter: W
Question
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 Reverselt. 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 character 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 stop.Explanation / Answer
#include<iostream>
using namespace std
void ReverseIt(char *str, int s)
{
for(int i=s-1;i>=0;i--)
{
cout<<str[I];
}
}
int main()
{
char str[50];
int i;
cin>>str;
cout<<str;
for(i=0;i<50;i++)
{
if(str[i]!='')
i++;
else
break;
}
ReverseIt (str,i);
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.