Perhaps you forgot to call the read_pricelist function?
Also, you should not use feof to control the loop in that way. Rather, use the return value of fscanf:
Code:
i = 0;
while (fscanf(file, "%s %f", items[i], &prices[i]) == 2) {
printf("%s %f\n", items[i], prices[i]);
i++;
}
However, this is still problematic in that items[i] presumably can store a string at most MAX_LENGTH - 1 in length. You need to account for this when reading to avoid buffer overflow, e.g.,
Code:
char scan_format[16];
sprintf(scan_format, "%%%ds %%f", MAX_LENGTH - 1);
i = 0;
while (fscanf(file, scan_format, items[i], &prices[i]) == 2) {
printf("%s %f\n", items[i], prices[i]);
i++;
}
Also, it would probably be better to return an error code instead of exiting immediately if the file cannot be opened. Perhaps at some later point you might want to allow the user to try again with a different file name.