I'm trying to read the numbers after a colon and store the value in a variable, but when I print it, it prints a random 6 digit number. I only need to store the value, not the 'ms' or 'degrees'.
For example, the text file is similar to this, but repeats for 100 set of values:
time: 20 ms
temperature: 50.5 degrees
lightvalue: 30
value1: 0.59
value2: 1
value3: 0
----------------------
time: 40 ms
temperature: 37 degrees
lightvalue: 10
value1: 1.57
value2: 0
value3: 1
----------------------
I want to store each number in a separate variable.
Here is part of my code:
int time[10];
double temperature[10];
int lightvalue[10];
double value1[10];
int value2[10];
int value3[10];
for (int i = 0; i < 100; i++) {
fscanf(infile, "time: %i", &time);
fscanf(infile, "temperature: %d", &temperature);
fscanf(infile, "lightvalue: %i", &light);
fscanf(infile, "value1: %d", &val1);
fscanf(infile, "value2: %i", &val2);
fscanf(infile, "value3: %i", &val3);
//how to skip the "---------------" line?
}