title: How to do backspace processing in C
body: <p>How to do a backspace processing for string in C? Here is a simple example of what I wrote</p>
  
  <pre><code>char buf[1024]="D,e,Bs,a,t,e"  \\*Bs means Backspace
  char tmp[1024];
  int j,n;
  n=0;
  
  sprintf(tmp,"%s",buf);
  for(j=0;tmp[j] !='\0';j++)
  {
      if ((tmp[j] == '\x08') || (tmp[j] == 127))
      {
        j++;
        n--;
      }
      buf[n] = tmp[j];
      n++;
  }
  buf[n] = '\0';
  printf("%s",buf);
  </code></pre>
  
  <p>This will print = <code>Date</code></p>
  
  <p>But if the buf have more than 1 Bs, example</p>
  
  <pre><code>char buf[1024] = "D,e,e,Bs,Bs,a,t,e"
  </code></pre>
  
  <p>The output will be = <code>DeBsate</code></p>
  
  <p>The function will find only 1 backspace. Why? Because the j are increased after it process the first Bs and ignored checking the Bs after that. Of course, if check on terminal, the output are still date. But if I log the debug just to see the string inside buf. The second Bs will still be there. Which is not suppose to. How do I modify this function?</p>