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 |
|