I am reading a file like:
31 0A 34 0A 31 0A 38 0A 34 0A 33 0A 36
0A 31 0A 31 0A 39 0A 31 30 0A 31 30 0A
35 0A 35 0A 31 30 0A 31 0A 33 0A 36 0A
33 0A 31 30 0A 35 0A 31 0A 31 30 0A 39
0A 35 0A 38 0A 33 0A 36 0A 34 0A 33 0A
36 0A 35 0A 31 30 0A 37 0A 32 0A 36 0A
33 0A 36 0A 35 0A 31 30 0A 37 0A 39 0A
33 0A 36 0A 32 0A 36 0A 35 0A 34 0A
0A 30 20 31 20 34 37 32 37 0A 30 20
33 20 36 33 36 33 0A 30 20 34 20 33 36
35 37 0A 30 20 35 20 33 31 33 30 0A 30
20 36 20 32 34 31 34 0A 30
I am planning to reading The first part of the file with the following code, until to find the sequence 0A 0A:
readed = fscanf(f,"%s", str_aux);
After 0A 0A I need to read with the following sentence:
readed = fscanf(f,"%s %s %s", str_aux1, str_aux3, str_aux3);
How i could detect the 0A 0A in order to start reading the second part of the file.
I would like to use the following structure:
while (something){
readed = fscanf(f,"%s", str_aux);
}
while (fscanf(f, "%s %s %s", a,b,c)!= EOF){
...
...
}
some idea for something condition (inside the first while)?
I’m working on Linux.
If you insist on using fscanf, you can read one character at a time. For example,
I think this will do exactly what you want. This reads one character at a time until two consecutive 0x0A’s (newlines) occur. Then the loop breaks and you can go on to the second while loop.
I’ll agree with Seth, however, that fgets or fgetc would be more appropriate for the first loop.