title: error in debugging the algorithm
body: <p>I'm trying to make an algorithm in Matlab that scans the character array from left to right and if it encounters a space, it should do nothing, but if it encounters 2 consecutive spaces, it should start printing the remaining quantities of array from next line. for example, </p>
  
  <pre><code>inpuut='a bc  d';
  </code></pre>
  
  <p>after applying this algorithm, the final output should have to be:</p>
  
  <pre><code>a bc
  
  d
  </code></pre>
  
  <p>but this algorithm is giving me the output as:</p>
  
  <pre><code>a bc
  
  d d
  </code></pre>
  
  <p>Also, if someone has got a more simpler algorithm to do this task, do help me please :)</p>
  
  <pre><code>m=1; t=1;
  inpuut='a bc  d';
  
  while(m&lt;=(length(inpuut)))
  
      if((inpuut(m)==' ')&amp;&amp;(inpuut(m+1)==' '))
          n=m;
          fprintf(inpuut(t:(n-1)));
          fprintf('\n');
          t=m+2;
      end    
  
      fprintf(inpuut(t));
  
      if(t&lt;length(inpuut))
          t=t+1;
      elseif(t==length(inpuut))
          t=t-1;
      else
      end
  
      m=m+1;
  
  end
  fprintf('\n');
  </code></pre>