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

1) #include <stdio.h> 2) #define BUFSIZE 100 3) main() 4) { 5) char buf[BUFSIZE]

ID: 3822445 • Letter: 1

Question

1) #include <stdio.h>

2) #define BUFSIZE 100

3) main()

4) {

5) char buf[BUFSIZE];

6) char filename[20];

7) FILE *fp;

8) puts("Enter text file to open: ");

9) gets(filename);

10) if ((fp = fopen(filename, "r"))==NULL)

11) {

12) fprintf(stderr, "Error opening file.");

13) return(1);

14) }

15)

16) while ( !feof(fp) )

17) {

18) fgets(buf, BUFSIZE, fp);

19) printf("%s",buf);

20) }

21) fclose(fp);

22) }

Illustration 5:

54)In Illustration 5 which line declares a file pointer?

A) 18

B) 1

C) 10

D) 7

55)In Illustration 5 which line opens a file for text input?

A) 7

B) 18

C) 13

D) 10

56)In Illustration 5 which line outputs to stdout

A) 9

B) 10

C) 18

D) 19

57)In Illustration 5 which line 16 uses feof that returns what if the input file has been completely read in?

A) Yes

B) False

C) True

D) No

58)In Illustration 5 which line gets a file name from stdin?

A) 6

B) 18

C) 9

D) 8

59)In Illustration 5 in line 21, fclose calling argument is what?

A) pointer

B) value

C) file name

D) structure

60)In Illustration 5 which line closes stdout?

A) 21

B) none

C) 19

D) 7

Explanation / Answer

54)In Illustration 5 which line declares a file pointer?

A) 18

B) 1

C) 10

D) 7

Answer : 7) FILE *fp;

FILE is the declaration and *fp is the pointer

55)In Illustration 5 which line opens a file for text input?

A) 7

B) 18

C) 13

D) 10

Answer: 10) if ((fp = fopen(filename, "r"))==NULL)

fopen is the method to open file and r means read mode

56)In Illustration 5 which line outputs to stdout

A) 9

B) 10

C) 18

D) 19

Answer: 19) printf("%s",buf);

printf is the method to print and we are printing content in the file to console

57)In Illustration 5 which line 16 uses feof that returns what if the input file has been completely read in?

A) Yes

B) False

C) True

D) No

Answer: B)False

16) while ( !feof(fp) ) -- Explanation -- as long as we have some content in file, we will read and if end of file is reached, it will be False