Opdracht afgemaakt
authorChris <mail@chriskamphuis.com>
Fri, 6 Feb 2015 23:40:42 +0000 (00:40 +0100)
committerChris <mail@chriskamphuis.com>
Fri, 6 Feb 2015 23:40:42 +0000 (00:40 +0100)
ass1/chris/sws1-s4109503-s4202015/exercise2/Makefile [new file with mode: 0644]
ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome [new file with mode: 0755]
ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome.c [new file with mode: 0644]

diff --git a/ass1/chris/sws1-s4109503-s4202015/exercise2/Makefile b/ass1/chris/sws1-s4109503-s4202015/exercise2/Makefile
new file mode 100644 (file)
index 0000000..4d17b59
--- /dev/null
@@ -0,0 +1,4 @@
+all: parsegenome.c
+       gcc -o -Wall -o parsegenome parsegenome.c
+clean:
+       $(RM) parsegenome
diff --git a/ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome b/ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome
new file mode 100755 (executable)
index 0000000..df21604
Binary files /dev/null and b/ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome differ
diff --git a/ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome.c b/ass1/chris/sws1-s4109503-s4202015/exercise2/parsegenome.c
new file mode 100644 (file)
index 0000000..e5c1411
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]){
+       if(argc != 2){
+               printf("Not the right amount of arguments given");
+               return -1;
+       }
+  FILE *file = fopen(argv[1], "r");
+       if(file == 0){
+    return -1;
+       }
+       int a = 0;
+       int c = 0;
+       int g = 0;
+       int t = 0;
+       int amount_chars = 0;
+       char x;
+       while((x = fgetc (file) ) != EOF){
+         switch(x){
+                       case 'A':
+                       a += 1;
+                               amount_chars += 1;
+                               break;  
+                       case 'C':
+               c += 1;
+                               amount_chars += 1;
+                               break;  
+                       case 'G':
+               g += 1;
+                               amount_chars += 1;
+                               break;          
+                       case 'T':       
+               t += 1;
+                               amount_chars += 1;
+                               break;  
+                       case '\n':
+                               if(amount_chars % 100 != 0){
+                                       printf("%i", amount_chars);
+                                 printf("Not right format");
+                                       return -1;
+                               }
+                               break;
+                       default:
+                               return -1;
+                       }
+       }
+       if(amount_chars != 50000){
+               return -1;
+       }
+       printf("There were %i A's, %i C's, %i G's, %i T's\n",a,c,g,t);
+       return 0;
+}