From 2fad529502cd8990686d1a924477505b6888a4a6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 24 Oct 2010 17:14:41 -0400 Subject: [PATCH] Extend src/sorting/main.c to also read from stdin. --- src/sorting/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sorting/main.c b/src/sorting/main.c index 824e8c2..43fa55e 100644 --- a/src/sorting/main.c +++ b/src/sorting/main.c @@ -47,7 +47,9 @@ int read_data(const char *file_name, int *pList_size, double **pList) double x; // open the file - if ((fp = fopen(file_name, "r")) == NULL) { + if (strcmp("-", file_name) == 0) { + fp = stdin; + } else if ((fp = fopen(file_name, "r")) == NULL) { fprintf(stderr, "error in opening data file %s\n", file_name); return EXIT_FAILURE; } @@ -71,7 +73,8 @@ int read_data(const char *file_name, int *pList_size, double **pList) } // close the file - fclose(fp); + if (fp != stdin) + fclose(fp); return EXIT_SUCCESS; } -- 2.26.2