I've searched google and tried several different things but I can't figure out how to read strings into a two dimensional character array and also read doubles into separate arrays all from the same text file. Please provide any help you can and let me know how you might accomplish this. Here is the data in the text file as it appears. The '7' is suppose to let us know how many metals are present and should be stored in the array. Thanks in advance!
7
aluminum .012580 .003000 32. 1130.
cast-iron .005441 .001747 32. 1160.
ingot-iron .006375 .001636 32. 1380.
malleable-iron .006503 .001622 32. 930.
ingot-steel .006212 .001623 32. 1380.
copper .009278 .001244 32. 1160.
nickel .007652 .001023 32. 1830.
This is one thing I tried
void getDatabase(char metals[][METALSTR], double aValues[],
double bValues[], double minTemp[], double maxTemp[],
int *number) {
char fileName[METALSTR]; // Assume the file name is 29 characters or less
char metalName[35];
int i = 0;
printf("Enter metals database file name: ");
scanf("%s", &fileName);
FILE *inputFile = fopen(fileName, "r");
if (inputFile == NULL) {
printf("\nThe file specified is not valid.");
printf("\nThe program will now terminate.");
exit(0);
}
// Get the first number from the file which inidicates number of metals
fscanf(inputFile, "%d", &number);
printf("%d", number);
// Loop through to the end of the file and store data in arrays
while (fgetc(inFile) != EOF) != NULL) {
fscanf(inputFile, "%s", &metalName);
fscanf(inputFile, "%lf", aValues[i]);
fscanf(inputFile, "%lf", bValues[i]);
fscanf(inputFile, "%lf", minTemp[i]);
fscanf(inputFile, "%lf", maxTemp[i]);
printf("%s\n", metalName[i]);
printf("%lf\n", aValues[i]);
printf("%lf\n", bValues[i]);
printf("%lf\n", minTemp[i]);
printf("%lf\n", maxTemp[i]);
i++;
}}
int main() {
char metals[numMetal][METALSTR];
double aValue[numMetal];
double bValue[numMetal];
double minTemp[numMetal];
double maxTemp[numMetal];
int number = 0;
getDatabase(metals, aValue, bValue, minTemp, maxTemp, &number);
}
The code compiles but when I run the program it stops responding once it enters the while loop