Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C please and thanks Write a program to reverse the words of a string.

ID: 3864914 • Letter: H

Question

Help with C please and thanks

Write a program to reverse the words of a string. Implement a function reverse () that reverses the string between indexes i and j inclusively. Prototype of the function is given below. void reverse (char *str, int i, int j) An example is given in figure 1. If we have reverse (str, 0, 4) it reverses the string between indexes of 0 and 4 from apple to elppa. You can reverse all the words of a string by finding start and end positions of each word and reversing the word Assume that you have only uppercase and lowercase letters in the word. Sample execution is given below fox01> recitation7 Enter a string: apple orange banana Reversed string: elppa egnaro ananab

Explanation / Answer

Answer:

The implementation is written as below :

void reverse(char *str, int i, int j)
{
if(i>j)
{
int read=i;
i=j;
j=read;
}
char read;
while(i<j)
{
read=str[i];
str[i]=str[j];
str[j]=read;
i++;
j--;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote