Opdracht afgemaakt
[sws1-1415.git] / ass1 / chris / sws1-s4109503-s4202015 / exercise2 / parsegenome.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main(int argc, char *argv[]){
5 if(argc != 2){
6 printf("Not the right amount of arguments given");
7 return -1;
8 }
9 FILE *file = fopen(argv[1], "r");
10 if(file == 0){
11 return -1;
12 }
13 int a = 0;
14 int c = 0;
15 int g = 0;
16 int t = 0;
17 int amount_chars = 0;
18 char x;
19 while((x = fgetc (file) ) != EOF){
20 switch(x){
21 case 'A':
22 a += 1;
23 amount_chars += 1;
24 break;
25 case 'C':
26 c += 1;
27 amount_chars += 1;
28 break;
29 case 'G':
30 g += 1;
31 amount_chars += 1;
32 break;
33 case 'T':
34 t += 1;
35 amount_chars += 1;
36 break;
37 case '\n':
38 if(amount_chars % 100 != 0){
39 printf("%i", amount_chars);
40 printf("Not right format");
41 return -1;
42 }
43 break;
44 default:
45 return -1;
46 }
47 }
48 if(amount_chars != 50000){
49 return -1;
50 }
51 printf("There were %i A's, %i C's, %i G's, %i T's\n",a,c,g,t);
52 return 0;
53 }