Write a program to reverse the order of the words.
Example:- I am awesome
Result: awesome am I
#include<stdio.h> #include<string.h> void Reverse_Word_order(char*); int main() { char s[100]; printf("Enter String = "); scanf("%[^\n]",s); Reverse_Word_order(s); printf("%s\n",s); return 0; } void Reverse_Word_order(char*p) { int i,m,n; char ch; for(m = 0, n = strlen(p)-1;m < n;m++,n--) { ch = p[m],p[m] = p[n],p[n] = ch; } for(i = 0;p[i];i++) { m = i; for(;p[i]!=32 && p[i];i++); n = i-1; for(;m < n;) { ch = p[m]; p[m] = p[n]; p[n] = ch; m++,n--; } } }
Output
Enter String = Learn To Lot Lot To Learn