C: save values from a text file to a memory field

104 Views Asked by At

I am trying to open a text file and save the float values to a specific memory-address to work with them in an assembly-program. My problem is that I have a restriction to the format of the values in the text file:

if(sscanf(line,"%f  mm  %f  mm", 
  &data1[linesread], &data2[linesread]) != 2)
{
    fprintf(stderr, "Error in line: %s\n",line);
    fprintf(stderr, "Aborted.");
    break;
}

What does %f mm %f mm in sscanf() stand for?

%f means that the first and the second value of the line have to be a float-value but I don't understand what "mm" means.

When I try to read in a line formatted like this:

5.0 2.0

I always get:

Read: 5.0 2.0
Error in line: 5.0 2.0

Aborted.
2

There are 2 best solutions below

0
On

Maybe you can try this

if(sscanf(line, "%f %f", &data1p[linesread], &data2[linesread]) != 2)
0
On

Both your code and the input file need to agree if the mm's should be present.

As Jurica says, remove the two mm's from your code. Alternatively, you could try Paul's suggestion of adding the two mm's in your input file. The correct solution for you depends upon the format restrictions of your input file.

My guess is that mm means millimeters, which is probably the units of your data.