Use strtol instead of atol; verify conversion.
Include cstdlib just in case.