Using atoi() while reading from a file and it is dropping the first 0 in some of the zip codes, for example:
int x = atoi("06461");
seems to be saving x = 6461. Is dropping non significant 0’s part of the atoi function?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It doesn’t drop zero. It stores the number. And as a number (decimal) 06461 and 6461 is exactly the same value. It’s up to you how to present the number — with (
printf("%05d",zip)) or without (%din case ofprintf) leading zero.P.S. Note, that c folks are mightily confused by leading zeros, they tend to see numbers as octal then.
P.P.S. And I fully support Joachim’s comment to your question.