aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcount_nucleobases.c33
1 files changed, 8 insertions, 25 deletions
diff --git a/count_nucleobases.c b/count_nucleobases.c
index 0396ea6..d1a4f1c 100755
--- a/count_nucleobases.c
+++ b/count_nucleobases.c
@@ -5,10 +5,6 @@
#include <stdint.h>
int main(int argc, char **argv) {
- long unsigned long a = 0;
- long unsigned long c = 0;
- long unsigned long g = 0;
- long unsigned long t = 0;
if(argc != 2) {
printf("Please supply a filename, and only a filename\n");
@@ -21,33 +17,20 @@ int main(int argc, char **argv) {
}
char line[8192];
+ long unsigned long counts[256];
while (fgets(line, 8192, fh) != NULL) {
- int i = 0;
-
+ unsigned 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;
- }
+ counts[line[i]]++;
}
}
- printf("A:%llu\nC:%llu\nG:%llu\nT:%llu\n", a, c, g, t);
+ printf("A:%llu\nC:%llu\nG:%llu\nT:%llu\n",
+ counts['a'] + counts['A'],
+ counts['c'] + counts['C'],
+ counts['g'] + counts['G'],
+ counts['t'] + counts['T']);
return EXIT_SUCCESS;
}