Extend src/sorting/main.c to also read from stdin.
authorW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 21:14:41 +0000 (17:14 -0400)
committerW. Trevor King <wking@drexel.edu>
Sun, 24 Oct 2010 21:14:41 +0000 (17:14 -0400)
src/sorting/main.c

index 824e8c2fc013464b5e9197ae275909bafd1b2a9c..43fa55eb1d7a23d3f6703b351dbf15d03a812726 100644 (file)
@@ -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;
 }