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.
You'll need to create a data structure to hold them and then a vector of this struct which will hold each currency read. You should make use of the fscanf function that will not only save you from splitting values by hand but will also convert them for you. Here is something I came up with:
/* to store each currency you read */
struct currency {
char name[256];
double value;
};
int main(int argc, char ** argv) {
FILE * fp = fopen("x.dat", "r");
int count = 0, i;
struct currency currencies[30];
/* this will read at most 30 currencies, and stop in case a
* end of file is reached */
while (count < 30 && !feof(fp)) {
/* fscanf reads from fp and returns the amount of conversions it made */
i = fscanf(fp, "%s %lf\n", currencies[count].name, ¤cies[count].value);
/* we expect 2 conversions to happen, if anything differs
* this possibly means end of file. */
if (i == 2) {
/* for the fun, print the values */
printf("got %s %lf\n", currencies[count].name, currencies[count].value);
count++;
}
}
return 0;
}
To read them again, you'll need to iterate on the currencies array until you reach count iterations.
Since you already wants to match those values with the strcmp function, read the currency name, iterate on the array until you find a match and then perform calculations on those.
This is basic C knowledge and as much as I understand you're not used to using it, I strongly suggest you read a book to find these answers in them.