title: How to remove spaces that are in a string sentence
body: <p>I am trying to write a code to remove all the leading, trailing and middle of the sentence spaces but to keep only one space between the words.</p>
  
  <p>For example if the input is</p>
  
  <pre><code>"    This    is my     string    "
  </code></pre>
  
  <p>the output should be</p>
  
  <pre><code>"This is my string"
  </code></pre>
  
  <p>So far I have come up with this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  void cascade(char str[], int i);
  main()
  {
      char str[100] = "    This    is my     string    ";
      int i = 0;
      while (str[i] != '\0') {
              if (str[i] == ' ' &amp;&amp; str[i + 1] == ' ')
                      cascade(str, i);
              i++;
      }
      printf("%s\n", str);
  }
  
  void cascade(char str[], int i)
  {
      while(str[i] != '\0') {
              str[i] = str[i + 1];
              i++;
      }
      str[i + 1] = '\0';
  }
  </code></pre>
  
  <p>I would appreciate if anyone could come up with some ideas, Thank you.</p>