-
Reading of a *.CSV File
Quick question for all of you great experts out there...I have a file called Currency Conversion Rates.csv that I was wondering if there is a way to read the entire file into an array, 24x24 ([24] [24] for doing some mathematical operations. Should I include a copy of the file here so that you can see what the data looks like? (The data can all be defined as float).
-
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?