title: Using backspace with ncurses
body: <p>I have a simple ncurses program set up that reads characters one at a time with getch() and copies them into a buffer. The issue I am having is detecting a press of the backspace key. Here is the relevant code:</p>
  
  <pre><code>while((buffer[i] = c = getch()) != EOF) {
      ++i;
      if (c == '\n') {
          break;
      }
      else if (c == KEY_BACKSPACE || c == KEY_DC || c == 127) {
          i--;
          delch();
          buffer[i] = 0;
      }
      refresh();
  }
  </code></pre>
  
  <p>But when attempting to run this code, this is what appears on the screen after trying to delete characters from the line "this is a test":</p>
  
  <pre><code>this is a test^?^?^?
  </code></pre>
  
  <p>and the contents of <code>buffer</code> are:</p>
  
  <pre><code>this is a test
  </code></pre>
  
  <p>With gdb I know that the if statement checking for a delete/backspace is being called, so what else should I be doing so that I can delete characters?</p>