Hello all - I have a simple program that mimics taking in a password in the terminal. To do this I turn off echoing and Icanon so that I can process each char as it is typed. I check if the current char value is in the printable ASCII range before printing it, however this fails to catch non ascii input such as the page down or home key.

Heres the part of the code that I am having trouble with:
Code:
  //check ASCII range, dont allow non printable chars
  //the var c is the current character that was input
  if(c > 32 && c < 127){
      buf[len++] = c;
      putchar('*');      //print an '*' for each char input
      }
  }
  else{
    //print diff char just for debugging
    putchar('#')
  }
The else block does get called when I hit a non ascii key like page up, but then prints a few '*', as if it processed more then just one character. Here is the output when run and only entering a single page up key stroke:
Enter password: #***

So the else block does catch it at first, yet then 3 more characters are printed even though my loop should only process one at a time since I only have a single char variable and terminal buffering is off. Any help would be great, as I'm pretty stuck on how to filter out these invalid keystrokes.