From: W. Trevor King Date: Sun, 24 Oct 2010 21:14:41 +0000 (-0400) Subject: Extend src/sorting/main.c to also read from stdin. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2fad529502cd8990686d1a924477505b6888a4a6;p=parallel_computing.git Extend src/sorting/main.c to also read from stdin. --- 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; }