//Reverse String word by word
// if string is :- I am a good boy
//output string should be :- boy good a am I
#include<stdio.h>
#include<string.h>
void reverse(char *p,char*q)
{
    int i;char c;
    while(p<q)
    {
        c=*p;*p=*q;*q=c;
        p++;
        q--;
    }
}

void reverseWordByWord(char str[],int len)
{
    int i=0,j=0;

     while(i<len)
     {

        if((str[i]==' ')||(str[i]=='\t')||(str[i]='\0'))
        {
            reverse(&str[j],&str[i-1]);
            j=i+1;
        }
        i++;
     }
}

int main()
{
    char A[]="Ram is a good person";
    int i;
    int len=strlen(A);
    reverse(&A[0],&A[len-1]);
    printf("%s\n",A);
    reverseWordByWord(A,len);
    printf("%s\n",A);
    return 0;
}


-- 
**With Regards
Deoki Nandan Vishwakarma

*
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to