I'm trying to read data from a .txt file with fscanf(), but it won't find values in the file. I want to skip certain values and read some integers as well as floating point numbers, all separated by commas.
I've looked through several threads where people have similar issues, but so far I have not been able to apply any of the recommendations to my case.
The file looks like this:
EURUSD,5,20211224,000000,1.13289,1.1329,1.13273,1.13273,0,0 EURUSD,5,20211224,000500,1.13273,1.13273,1.13233,1.13242,0,0 EURUSD,5,20211224,001000,1.13243,1.13265,1.13233,1.13253,0,0 EURUSD,5,20211224,001500,1.13258,1.13295,1.13253,1.13279,0,0 EURUSD,5,20211224,002000,1.13279,1.13297,1.13255,1.13277,0,0
I open it with
FILE* fivemin = fopen("eurusd.txt", "r");
and then format the input as follows:
while (fscanf(fivemin, "%*s,%*d,%d,%d,%lf,%lf,%lf,%lf,%*d,%*d", &day, &timeat, &ropen, &rhigh, &rlow, &rclose) ==6) {
printf("%d %d %lf %lf %lf %lf\n", day, timeat, ropen, rhigh, rlow, rclose);
}
The code is executed and the values of day,timeat, ropen, rhigh, rlow and rclose do not change.
Adding or removing \n or \0 to the end of the input format line doesn't help.I've compared fscanf return value to 0 and it doesn't help either, which means that fscanf() can't find anything.
I would appreciate it if someone could tell me what I am doing wrong and how I could scan the values with fscanf() properly.