aboutsummaryrefslogtreecommitdiff
path: root/count_nucleobases.c
diff options
context:
space:
mode:
Diffstat (limited to 'count_nucleobases.c')
-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;
+ }
}
}