I've been trying to scan integers with sscanf()
from strings with leading zeros (e.g. '03').
However, it works fine but only until '07'. Starting with '08', the strings will be read as 0.
Below you'll find my code and the output. Thank you for your help!
#include <stdio.h>
#include <stdlib.h>
int main() {
char string_six[3] = "06";
char string_seven[3] = "07";
char string_eight[3] = "08";
char string_nine[3] = "09";
int six = -1;
int seven = -1;
int eight = -1;
int nine = -1;
sscanf(string_six, "%i", &six);
sscanf(string_seven, "%i", &seven);
sscanf(string_eight, "%i", &eight);
sscanf(string_nine, "%i", &nine);
printf("Six: %i\n",six);
printf("Seven: %i\n",seven);
printf("Eight: %i\n",eight);
printf("Nine: %i\n",nine);
return 0;
}
Output:
Six: 6
Seven: 7
Eight: 0
Nine: 0