title: Replace multiple spaces by single space in C
body: <p>I want to repace multiple spaces in a string by single space, however my following code doesn't work. What's the logical mistake?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  main()
  {
  char input[100];
  int i,j,n,z=0;
  scanf("%d",&amp;n);
  z=n;
  for(i=0;i&lt;n;i++)
  scanf("%c",&amp;input[i]);
  for(i=0;i&lt;n;i++)
  {
      if(input[i]==' ' &amp;&amp; (input[i+1]==' ' || input[i-1]==' '))
      {
          --z;
          for(j=i;j&lt;n;j++)
          input[j]=input[j+1];
      }
  }
  for(i=0;i&lt;z;i++)
      printf("%c",input[i]);
  printf("\n");
  }
  </code></pre>