Question: Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place
Reverse the given string word wise. That is, the last word in given string should come at 1st place, last second word at 2nd place and so on. Individual words should remain as it is.
I wrote the solution but I am getting runtime error why?
assume the variables j ant t as start and end respectively.
void reverseStringWordWise(char input[]) {
int n=0;
int k=0;
char temp;
for(int i=0;input[i]!='\0';i++)
{
n++;
}
for (int i = 0, j = n - 1 - i; i < j; i++, j--) {
temp = input[i];
input[i] = input[j];
input[j] = temp;
}
while(input[k]!='\0')
{
int j=k;
while(input[k]!=' ' || input[k]!='\0')
{
k++;
}
int t=k-1;
while(j { temp = input[j]; input[j] = input[t]; input[t] = temp; j++; t--; } k++; if(k>n) break; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
