title: How to erase last char in console using backspace, without using space char?
body: <p>I'm trying to implement a console program that has backspace functionality. The console accepts a number of valid commands I've defined. Example:</p>
  
  <p>Input:</p>
  
  <p><a href="https://i.stack.imgur.com/qUaS4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qUaS4.png" alt="enter image description here"></a></p>
  
  <p>Output:</p>
  
  <p><a href="https://i.stack.imgur.com/tEq32.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tEq32.png" alt="enter image description here"></a></p>
  
  <p>I'm using a switch statement, which checks the current char returned by <code>getchar()</code>. </p>
  
  <pre><code>    switch (inChar)
      {
          case '\r':
          case '\n':
          {
              ...
          }
  
          case 0x18:                      // ^x
          {
              ...
          }
  
          case 0x08:                     // backspace
          {
              printf("\b \b");
              break;
          }
  
          default:
          {
              inBuffer[inBufIndx++] = inChar;
              inBuffer[inBufIndx] = 0;
              printf("%c", inChar);       // echo character
          }
      }
  </code></pre>
  
  <p>The code above gives the appearance of erasing the character, but places a space char. This works for most instances, such as erasing the <code>o</code> off of <code>helo</code> but does not work when erasing the <code>o</code> off <code>helpo</code>. My shell can no longer interpret the command due to the space char that is printed in the place of the <code>o</code></p>
  
  <p>How can I implement backspace for chars at the end of the inputthat need to be erased?</p>
  
  <p><strong>EDIT:</strong> rici is exactly right. I was not removing the char I erased in the console from my inBuffer. The code below gave the desired functionality.</p>
  
  <pre><code>        case 0x08:
          {
              printf("\b \b");
              inBuffer[inBufIndx--] = NULL;
              break;
          }
  </code></pre>