So this function reads in integers from a file that are separated by spaces and gets the total. It works fine.
As long as the numbers are single digit, 1-9.
How do I make it read double digit numbers from 1-100 ?
Do I make a nested if within the ifs that read every number and then try to read a second number right next to it without space and then go for the third digit (case 100)?
And then I make them into an integer (which to be honest I have no idea how to do)
void get_total(FILE*fp){
char c;
int total=0;
int number_of_conversions;
number_of_conversions = fscanf(fp, "%c", &c);
while (isdigit(c) || isspace(c) && c !='\n' && c !=NULL){
if (isspace(c)){
number_of_conversions = fscanf(fp, "%c", &c);
}
else if (isdigit(c)){
total = total + (c- '0');
number_of_conversions = fscanf(fp, "%c", &c);
}
number_of_conversions = fscanf(fp, "%c", &c);
}
printf("%d", total);
}