Answers for "Write a program that takes one string input and reverse the string in such a way that [4] each word will be reversed in its own position."

0

Write a program that takes one string input and reverse the string in such a way that [4] each word will be reversed in its own position.

#include<stdio.h>
void rev(char str[], int start, int end)
{
    char temp;
    while(start<end)
    {
        temp=str[start];
        str[start]=str[end];
        str[end]=temp;
        start++;
        end--;
    }
}
int main()
{
    char str[1000];
    printf("Please input your string:");
    gets(str);
    int start, end;
    end=0;
    start=0;
    while(str[end])
    {
        for(end=start;str[end]&&str[end]!=' ';end++);
        rev(str, start, end-1);
        start=end+1;
    }
        printf("%s ",str);
    return 0;
}
Posted by: Guest on August-24-2021

Code answers related to "Write a program that takes one string input and reverse the string in such a way that [4] each word will be reversed in its own position."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language