Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the code at the right, and answer the following three (3) questions. Wh

ID: 3807776 • Letter: C

Question

Consider the code at the right, and answer the following three (3) questions. Which ONE of the following statements is TRUE about the data file being accessed by this code? Circle the letter next to ONE response. a. The file must exist for the fopen call to succeed. b. If the file exists, it will be erased and replaced with brand new contents. c. We expect the file's contents to begin with an integer value. d. The file will be created automatically, if it doesn't already exist. e. If the file contains no data at all (i.e., the file is empty), the cull to the fscanf function will succeed, and a value read from the file will be printed. Which ONE of the following is a FALSE statement about the fscanf function cull used in this code? Circle the letter next to ONE response. a. fscanf will return a 1, if it successfully reads and stores the requested double value. b. fscanf will read a double value from the keyboard, and store that double value into the val variable. c. fscanf's parameters are just like those of the scanf function, except that fscanf requires an additional first parameter that indicates which file to read the data from. d. fscanf will fail if the first thing it finds in the file is something that can't be interpreted as a double (if it finds the word orange, for example). Which ONE of the following statements is TRUE about the behavior of this code? Circle the letter next to ONE response. a. If it successfully opens the data file, and if it successfully reads a double value from that data file, the square of that value will be printed in the console window. b. If it successfully opens the data file, and if it successfully reads a double value from that data file, nothing will be printed in the console window. c. If the data file doesn't exist, an error message will be printed in the console window. d. If it successfully opens the data file, it will never close the data file. FILE *fp; fp = fopen("c:\data\myfile.txt", "r"); if (fp != NULL) // if fopen succeeded { double val; if (fscanf(fp, "%1f", %val) -- 1) { printf("%f ", val * val); } fclose(fp); }

Explanation / Answer

1. a.the file must exit for the fopen call to succed

2. c.fscan parameter are just like those of the scanf function , except that fscanf required an additional first parameter that indicates which files read the data from.

3.b. if it successfully open the data file , and if it successfully read a double value from that data file , nothing will be printed in the console window