aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2013-08-30 14:15:26 -0400
committerCalvin Morrison <mutantturkey@gmail.com>2013-08-30 14:15:26 -0400
commit17a506ed4e3f3c0ee89257549d2b4f0ea82cb899 (patch)
tree05f348ffb8b28ba4051f2168fc6fa4e90feb828f
parent961479f0cb46b4ef5bf59548b94058358906454d (diff)
proper check, and use fgest instead of getc
-rwxr-xr-xcount_nucleobases.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/count_nucleobases.c b/count_nucleobases.c
index 2f3dce8..0396ea6 100755
--- a/count_nucleobases.c
+++ b/count_nucleobases.c
@@ -16,29 +16,34 @@ int main(int argc, char **argv) {
}
FILE *fh = fopen(argv[1], "r" );
if(fh == NULL) {
- fprintf(stderr, "could not open dna.txt\n");
+ fprintf(stderr, "Couldn't open: %s\n", argv[1]);
exit(EXIT_FAILURE);
}
- int ch = 0;
- while ((ch = getc(fh)) != EOF) {
- switch(ch) {
- case 'A':
- case 'a':
- a++;
- break;
- case 'C':
- case 'c':
- c++;
- break;
- case 'G':
- case 'g':
- g++;
- break;
- case 'T':
- case 't':
- t++;
- break;
+ char line[8192];
+ while (fgets(line, 8192, fh) != NULL) {
+
+ int i = 0;
+
+ for(i = 0; i < strlen(line); i++) {
+ switch(line[i]) {
+ case 'A':
+ case 'a':
+ a++;
+ break;
+ case 'C':
+ case 'c':
+ c++;
+ break;
+ case 'G':
+ case 'g':
+ g++;
+ break;
+ case 'T':
+ case 't':
+ t++;
+ break;
+ }
}
}