Try this one... #include<stdio.h> #include<string.h> void reverse(char *p,char*q) { char c; while(p<q) { c=*p;*p=*q;*q=c; p++; q--;
} } int main() { char A[50]; printf("\n Enter a String:\n\n"); gets(A); int len=strlen(A); reverse(A,&A[len-1]); printf("%s\n",A); return 0; } On Sun, Sep 25, 2011 at 10:51 AM, Dheeraj Sharma < dheerajsharma1...@gmail.com> wrote: > u shud do TWO things in..your reverseword function.. > first is str[i]=='\0' and not str[i]='\0' > second is while(i<=len) and not while(i<len) > > > On Sun, Sep 25, 2011 at 6:49 AM, Deoki Nandan <deok...@gmail.com> wrote: > >> //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. >> > > > > -- > *Dheeraj Sharma* > Comp Engg. > NIT Kurukshetra > > > > -- > 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. > -- *Avinesh Kumar, MCA NIT Calicut. * -- 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.