atoi and leading 0's for decimal numbers
问题 When using atoi in C I am trying to convert a char array of numbers to an int . I have leading 0 's on my number though and they are not preserved when I print the number out later. char num[] = "00905607"; int number; number = atoi(num); printf("%d", number); The output from this will be 905607 and I would like it to be 00905607 . Any ideas? 回答1: Use strtol instead. It allows you to specify the base. 回答2: You can do padding on your printf() so if you wanted every output to be 8 characters