Given a sentence in a form of a string, reverse string in this manner...for e.g. string is " please keep smile " then reverse is "smile keep please"
#include<stdio.h> void word(char *ptr,int n) { int j; char c; for(j=0;j<n/2;j++) { c=ptr[j]; ptr[j]=ptr[n-j-1]; ptr[n-j-1]=c; } } void strev(char *tpr,int i) { word(tpr,i); int k=0,j; for(j=0;j<=i;j++) { if(tpr[j]==' ' || tpr[j]=='\0') { word(tpr+k,j-k); } if(tpr[j]==32) { k=j+1; } } } int main() { char str[100]; int l=0; printf("enter string\n"); gets(str); while(str[l]!='\0') { l++; } strev(str,l); printf("%s",str); return 0; }