Without looking to in depth into you program it looks like your program will try to read forever if no -1 is found. I suggest that you read all of the input into one string and then split the string by a -1. This would keep you from needing an ending -1.
__________________
Void
|