title: how to perform reversing a sentence Word by Word in C?
body: <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
    int i,j;
    int wordstart = -1;
    int wordend = -1;
    char words[]= "this is a test";
    char temp;
  
    // Reverse each word
    for (i = 0; i &lt; strlen(words); ++i)
    {
      wordstart = -1;
      wordend = -1;
      if(words[i] != ' ') 
        wordstart = i;
      for (j = wordstart; j &lt; strlen(words); ++j)
      {
        if(words[j] == ' ')
        {
          wordend = j - 1;
          break;
        }
      }
      if(wordend == -1)
        wordend = strlen(words);
      for (j = wordstart ; j &lt;= (wordend - wordstart) / 2; ++j)
      {
        temp = words[j];
        words[j] = words[wordend - (j - wordstart)];
        words[wordend - (j - wordstart)] = temp;
      }
      i = wordend;
      printf("reversed string is %s:", words);
    }
  }
  </code></pre>
  
  <p>I tried in this way but i am getting this output:<br>
  <code>siht is a test</code><br>
  my expected output is:<br>
  <code>test a is this</code></p>
  
  <p>I would appreciate if some one could come with a different approach for which time complexity is very less or correct me if it is the right approach. Thanks</p>