This is suppose to calculate the BMI of someone. I have Hints but I still don't really know where to start... Can anyone give me some suggestions? Code: // hint: you're going to need to include another library to make the file functions below work right. /* * Task: create a program that reads a bmi file and outputs bmi to stdout * * The BMI file is formatted like this: * 105, 66 * 104.8, 58.2 * * Where the first column is the weight in pounds and the second column is the height in inches * * * The output should look like this: * Height: 66 inches; Weight: 105 lbs; BMI: bla * */ int main(int argc, char *argv[]) { if (argc < 2) { printf("Missing filename. Usage: %s <filename>\n", argv[0]); } char line[20]; // variable to store one line at a time from the file FILE * infile_fp; // variable to store the file pointer infile_fp = fopen(argv[1], "r"); // open the file passed on the command line // read the file one line at a time while (fgets(line, 20, infile_fp)) { float weight, height; // write a line here that breaks the weight and height out of the string // hint, try sscanf() printf("Height: %4.2f inches; Weight: %4.2f lbs; BMI: %4.2f\n", height, weight, bmi(weight, height));
Function counting BMI Code: float bmi(float weight, float height) { return (weight * 703) / (height * height); } You should end program in case of error Code: if (argc < 2) { ... return -1; } ... if (!infile_fp) { printf("Error opening file %s\n", argv[0]); return -2; } sscanf() format in this case Code: sscanf(line, "%f, %f", &weight, &height);