there's a few you're not checking, and atoi is notoriously bad. use strtoul and check the error state if you want to be more correct.