C Program to reverse words in the given String

How to write a C Program to Reverse Order of Words in a String with an example. Implementation: #include <stdio.h>
#include <string.h>

int main()
{
char str[100];
int i, len;

printf("\n Please Enter any String : ");
gets(str);

len = strlen(str);
printf("\n #### Given String in Reverse Order #### \n");

for(i = len - 1; i >= 0; i--)
{
if(str[i] == ' ')
{
str[i] = '\0';
printf("%s ", &(str[i]) + 1);
}
}
printf("%s", str);

return 0;
} Output:
Please Enter any String: We love Programmersdoor
#### Given String in Reverse Order ####
Programmersdoor love We Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Follow Programmers Door for more. #programming #blog #interview #placement #reverse_string

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door