blob: 6edf5e856b745df15d784dfe192a4c1239701bc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
main() {
long unsigned long a = 0;
long unsigned long c = 0;
long unsigned long g = 0;
long unsigned long t = 0;
FILE *fh = fopen("dna.txt", "r" );
if(fh == NULL) {
fprintf(stderr, "could not open dna.txt\n");
exit(EXIT_FAILURE);
}
unsigned 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;
}
}
printf("A:%lu\nC:%lu\nG:%lu\nT:%lu\n", a, c, g, t);
}
|