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

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!