benchmarks.larceny/src/sum1.c
raw| 1 | #include <stdio.h> |
| 2 | |
| 3 | int main(int argc, char *argv[]) |
| 4 | { |
| 5 | double s = 0, d; |
| 6 | FILE *fp; |
| 7 | char *infile = "../../src/rn100"; |
| 8 | if (argc > 1) |
| 9 | infile = argv[1]; |
| 10 | fp = fopen(infile, "r"); |
| 11 | if (fp == NULL) { |
| 12 | fprintf(stderr, "can't open %s\n", infile); |
| 13 | exit(1); |
| 14 | } |
| 15 | |
| 16 | while (fscanf(fp,"%lf", &d) != EOF) |
| 17 | s += d; |
| 18 | printf("%f\n", s); |
| 19 | return 0; |
| 20 | } |