change name
[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 FILE *f;
13 int c = 0;
14 int charsperline = 0;
15 int numlines = 0;
16 int occs[4] = {0, 0, 0, 0};
17
18 f = fopen(argv[1], "r");
19 if(f == NULL)
20 {
21 printf("Unable to open file...");
22 return 2;
23 }
24
25 while((c = fgetc(f)) != EOF)
26 {
27 if(c == '\n')
28 {
29 if(charsperline != 100)
30 return -1;
31 numlines += 1;
32 charsperline = 0;
33 }
34 else
35 {
36 if(c == 'A')
37 occs[0] += 1;
38 else if(c == 'C')
39 occs[1] += 1;
40 else if(c == 'G')
41 occs[2] += 1;
42 else if(c == 'T')
43 occs[3] += 1;
44 else
45 return -1;
46 charsperline += 1;
47 }
48 }
49 fclose(f);
50 if(numlines != 500)
51 return -1;
52
53 printf("A: %d\nC: %d\nG: %d\nT: %d\n", occs[0], occs[1], occs[2], occs[3]);
54 return 0;
55 }