The fgets() function reads a line of data from a file into a buffer. The sscanf() function extracts values from a buffer and puts them in variables based on a format string.
So if we have a file looking like this:
Code:
1.345, 34.527, 54.9
56.988, 0.7, 397.0
we might write code like this:
Code:
while (fgets(...)) /* Read a line of text from the file. */
{
/* Extract the float values and put them in an array. */
sscanf(buf, "%f, %f, %f", &floatarr[0], &floatarr[1], &floatarr[2]);
}
If you want further help, could you provide a sample of the data and post the code that you have written and details on why it is not working?