Code:
int main()
{
// Declare variables
float G, vi, v, B, tstep, duration[100000], burnrate[100000], m, temp1, temp2, h = 500, total = 0, a, j;
int mi, ve, D, S, i;
FILE *inFile;
FILE *outFile; //Declare a file outFile
inFile = fopen("LAND2.txt", "r"); // Open file LAND2.txt to read
if (inFile == NULL)
{
printf("\nFailed to open the file.\n"); // If the file doesn't exist print out can't open file and exit.
exit (1);
}
// Read in values for Params and Data
else
{
printf("\nThe file LAND2.txt was opened successfully.\n\n");
fscanf (inFile, "Params\n"); // Read the Params line (on the first line)
fscanf (inFile, "%f\n", &G); // Read the first parameter, gravitational acceleration (on the next line)
fscanf (inFile, "%f\n", &vi); // Read the second parameter,initial downward velocity (on the next line)
fscanf (inFile, "%f\n", &B); // Read the third parameter, initial burn rate (on the next line)
fscanf (inFile, "%f\n", &tstep); // Read the fourth parameter, time step (on the next line)
fscanf (inFile, "%d\n", &mi); // Read the fifth parameter, initial fuel mass (on the next line)
fscanf (inFile, "%d\n", &ve); // Read the sixth parameter, fuel exhaust speed (on the next line)
fscanf (inFile, "%d,%d\n", &D,&S); // Read the Data and Solutions values
printf ("%f\n%f\n%f\n%f\n%d\n%d\n%d,%d\n", G, vi, B, tstep, mi, ve, D, S);
fscanf (inFile, "Data\n"); // Read the Data line
for ( i = 0; i < D; i++ )
{
fscanf(inFile, "%f,%f\n", &temp1, &temp2); // Read in burnrate andduration til EOF
temp1=duration[i];
printf("%f\n", duration[i]);
temp2=burnrate[i];
printf("%f\n", burnrate[i]);
}
fclose (inFile); // Close the file
}