From 1a1392cfed14578eaae020cdcf968d66e82d8e64 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Fri, 31 Jan 2014 10:45:38 -0500 Subject: read from stdin if -i not supplied, also add strerror for information if opening file doesn't work:fg --- kmer_total_count.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kmer_total_count.c b/kmer_total_count.c index 2f944d8..2b4f548 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -62,9 +62,16 @@ int main(int argc, char **argv) { } } if(filename == NULL) { - fprintf(stderr, "Error: filename (-i) must be supplied\n"); - exit(EXIT_FAILURE); + fprintf(stderr, "not input file specified with -i, reading from stdin\n"); + fh = stdin; } + else { + fh = fopen(filename, "r"); + if(fh == NULL) { + fprintf(stderr, "Could not open %s - %s\n", filename, strerror(errno)); + exit(EXIT_FAILURE); + } + } if(kmer == 0 && !kmer_set) { fprintf(stderr, "Error: kmer (-k) must be supplied\n"); exit(EXIT_FAILURE); @@ -74,12 +81,6 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - fh = fopen(filename, "r"); - if(fh == NULL) { - fprintf(stderr, "Could not open %s\n", filename); - exit(EXIT_FAILURE); - } - width = kmer_pow_four(kmer); unsigned long long *counts = kmer_counts_from_file(fh, kmer); -- cgit v1.2.3