atoi function, but need to consider several different cases