I am trying to read strings from a file and convert them to integers for storage in a struct. The strtol() function works well but removes any 0s from the start of the tokens. Is there any way I can keep them? The input file is formatted like the example below.
003345.755653
000046.003265
073532.003434
122280.065431
Input file ^^^
struct store{
int *age;
int *ref;
}rec[20];
char *token;
char*ptr;
while (!feof (filea)){
fgets(buffer, sizeof buffer, filea);
token = strtok(buffer, ".");
rec[count].age = malloc(10);
rec[count].age = strtol(token, &ptr, 10);
printf("Age: %i\n", rec[count].age);
token = strtok(NULL, ".");
rec[count].ref = malloc(10);
rec[count].ref = strtol(token, &ptr, 10);
printf("Ref: %i\n\n", rec[count].ref);
count++;
}
.in the file mean? Is it a decimal separator? If so, is it your plan to use two integers to store a single decimal number?