From 23bf96a37b3d06093a909b4c57315fc4ba70343b Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 20 Dec 2017 13:35:10 +0100 Subject: [PATCH] fix bug in reading double values --- dist-maketable.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dist-maketable.c b/dist-maketable.c index c9fb034..260e354 100644 --- a/dist-maketable.c +++ b/dist-maketable.c @@ -39,17 +39,17 @@ double * readdoubles(FILE *fp, int *number) x = calloc(limit, sizeof(double)); if (!x) - error(-1, 0, "Alloc"); + perror("alloc"); size_t linelen = 0; - char *line; + char *line = NULL; for (i = 0; i < limit; i++) { if (getline(&line, &linelen, fp) > 0) { if (line[0] == '#' || line[0] == '\r' || line[0] == '\n') continue; - fscanf(fp, "%lf", &x[i]); + sscanf(line, "%lf", &x[i]); ++n; } @@ -94,7 +94,7 @@ int * makedist(double *x, int limit, double mu, double sigma) table = calloc(DISTTABLESIZE, sizeof(int)); if (!table) { - perror("table alloc"); + perror("alloc"); exit(3); }