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...