Monday, 4 April 2016

C Program For Given A Long Sentence Reverse The Sentence Word By Word.

Example: Let the input string be “i like this program very much”. The function should change the string to “much very program this like i”


#include <stdio.h>
#include <stdlib.h>

int main()
{
    char text[100];
    int i,j;
    puts("\t\nEnter The String Want To Reverse Word By Word :\n\n");
    gets(text);
printf("\n\n ");
   
    strrev(text);
   
for(i=0;text[i]!='\0';i++)
    {
       if(text[i+1]==' ' || text[i+1]==NULL)
       {
           for(j=i;j>=0 && text[j]!=' ';j--)
            printf("%c",text[j]);
       }
       printf(" ");
    }
    getche();
}

Output:-

www.programmingwithbasics.com

1 comment:
Write comments
  1. thank u sir it is very helpful , for me. once again thank u very much.



    ReplyDelete

Recommended Posts × +