I normally use R, and have a lot of trouble understanding C. I need to read and store a data file, shown below, so that I can perform calculations on the data.
I suggest you
typedef struct{
char currency[10];
double rate;
}rate_currency;
in your main function you use getline
to read the file line by line :
while ((read = getline(&line, &len, fpt)) != -1) ...
Separate:
use strchr
to search for the space character
to separate currency name from currency rate
Insert :
declare an array of your previous struct :
rate_currency arrOfStruct[10];
then, insert one by one
for example :
arrOfStruct[0].currency = "dollar"; //after you read it and separated it... arrOfStruct[0].rate = 1.00;