I don't know how large or potential to hacking your program is, but I have found that you write your own function, using something like getchr, you control what comes in and where it goes and you can just stop it at the length of the buffer -1 (if using a fixed buffer ensuring a null ending string (don't forget to ensure that's there). Write it once and keep using it, you can also pass on parameters for buffer length and what are acceptable character.
There are lots of functions you can use that operate quick to check input. I got crap one time for letting a user enter anything, excluding the 'enter' key for passwords, but it makes for a tough password to crack if you have deletes, function keys and combo keys (I used the arrow keys to over-strike if they made a mistake). Note that some keyboards send different codes for the obscure. This was a LARGE financial institution. It was the security code entry point.