CS140 -- Midterm Exam: Q8 - Q11

The following code is for questions 8 through 11
#include "fields.h"

main()
{
  IS is;
  int total;
  int i, j;

  is = new_inputstruct(NULL);
  total = 0;

  while (get_line(is) >= 0) {
    for (i = 0; i < is->NF; i++) {
      if (sscanf(is->fields[i], "%d", &j) == 1) {
        total += ((i+1)*j);
      } else {
        fprintf(stderr, "Line %d field %d\n", 
                is->line, i);
        exit(1);
      }
    }
  }
  printf("%d\n", total);
}
The following choices will be for questions 8 through 11.
a. 5
b. 10
c. 15
d. 20
e. 22
f. 23
g. 28
h. 37
i. 38
j. 50
k. Line 2 field 0
l. Line 2 field 1
m. Line 2 field 2
n. Line 2 field 3
o. Segmentation Violation


Question 8: What is the output of the above program when the input is:
1 2 3
  4 5

Question 9: What is the output of the above program when the input is:
1 2 3
0 Jim Plank
0 4 5

Question 10: What is the output of the above program when the input is:
1 2 3
# 0 Jim Plank
0 4 5

Question 11: What is the output of the above program when the input is (the second line is blank):
1 2 3

4
0 2