Changed it to use fgets and sscanf.

Originally it used scanf, but that was vulnerable to buffer overflows.
Fgets has a limit on how much it takes, and sscanf reads from a string.