I am trying to read a file formatted in this general way:
Text Description: 12
Description2: 1
More descriptive things: 6
And I would like to read the numbers 12, 1, and 6 into variables.
I have tried code like this:
fscanf(fptr, "Text Description:%d",&desc1);
fscanf(fptr, "Description2:%d",&desc2);
fscanf(fptr, "More descriptive things:%d",&desc3);
But for some reason only the first variable is being populated. Does anyone know why this is the case?
Add space at the beginning of the string format to avoid the new line problems
fscanf(fptr, " Text Description:%d",&desc1);
fscanf(fptr, " Description2:%d",&desc2);
fscanf(fptr, " More descriptive things:%d",&desc3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With