#include <stdio.h>

double nextentry(FILE *fp) {
    double pr, num;

    int n = fscanf(fp, "%lf%lf", &pr, &num);

    return n == EOF ? 0 : pr*num;
}

int main(int argc, char** argv)
{
    double total = 0, x;
    FILE * ifp;
    if (argc == 1) { /* 没有参数，给用户提供错误信息 */
        printf("Missing data file name. Stop!\n");
        return 1;
    }

    if ((ifp = fopen(argv[1], "r")) == NULL) {
        printf("Can't open file: %s. Stop!\n", argv[1]);
        return 2;
    }

    while ((x = nextentry(ifp)) != 0.0)
        total += x;

    printf("Total price: %f\n", total);
    fclose(ifp);

    return 0;
}


