35beda02c28cacd10b6bbf1db60ad8cdb6a169d1
[sws1-1415.git] / ass1 / mart / sws1-s4109503-s4202015 / exercise2 / parsegenome.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char* argv[])
5 {
6 if(argc != 2)
7 {
8 printf("Usage: %s filepath\n", argv[0]);
9 return 2;
10 }
11
12 int c = 0;
13 int charsperline = 0;
14 int numlines = 0;
15 int occs[4] = {0, 0, 0, 0};
16
17 FILE *f = fopen(argv[1], "r");
18 if(f == NULL)
19 {
20 printf("Unable to open file...");
21 return 2;
22 }
23
24 while((c = fgetc(f)) != EOF)
25 {
26 if(c == '\n')
27 {
28 if(charsperline != 100)
29 return -1;
30 numlines += 1;
31 charsperline = 0;
32 }
33 else
34 {
35 if(c == 'A')
36 occs[0] += 1;
37 else if(c == 'C')
38 occs[1] += 1;
39 else if(c == 'G')
40 occs[2] += 1;
41 else if(c == 'T')
42 occs[3] += 1;
43 else
44 return -1;
45 charsperline += 1;
46 }
47 }
48 fclose(f);
49 if(numlines != 500)
50 return -1;
51
52 printf("A: %d\nC: %d\nG: %d\nT: %d\n", occs[0], occs[1], occs[2], occs[3]);
53 return 0;
54 }