Write a program such that it reverse all words but not the string. for example it input string is “i love programing” then its output should be “i  evol gnimargorp”.

#include<stdio.h>
#include<string.h>

int
main ()
{
  char str[] = "i love programing";
  printf ("The given string is:\n %s \n", str);

  /* logic */
  int str_size = strlen (str);
  int i = 0;
  int j = 0;
  int p = 0;
  printf("output is:\n");
  for (i = 0; i < str_size; i++)
    {
      j = i;
      while (str[j] != ' ' && str[j] != '\0')
    j++;
      p = j;
      while (j >= i)
    printf ("%c", str[j--]);
      printf (" ");
      i = p;
    }
  printf ("\n");

  return 0;
}



Related Contents to follow