1 #include <stdint.h> /* We save the all the frequencies in a 64 bit int */
2 #include <stdio.h> /* We extract/add them using bitshifts */
3 #include <stdlib.h> /* When no filepath is specified assume stdin */
6 int main(int argc
, char* argv
[])
8 char *alphabet
= "AGTC";
13 FILE *f
= argc
!= 2 ? stdin
: fopen(argv
[1], "r");
16 while((c
= fgetc(f
)) != EOF
)
17 if(c
== '\n' && charsperline
== 100 && numlines
++ < 500)
19 else if(strchr(alphabet
, c
) && charsperline
++ < 100)
20 occs
+= 1LL<<((int)(strchr(alphabet
, c
)-alphabet
)*16);
27 for(unsigned i
=0; i
<strlen(alphabet
); i
++)
28 printf("%c: %u\n", alphabet
[i
], (uint16_t)(occs
>> (16*i
)));