From c7f4694da515e2c1b128094a2a5678a02322feb0 Mon Sep 17 00:00:00 2001
From: Mickael Da Silva <mickael.dasilva@unistra.fr>
Date: Fri, 7 Feb 2020 13:54:33 +0100
Subject: [PATCH] utils

---
 Algos_1/main.c   | 33 +--------------------------------
 Algos_1/makefile |  7 +++++--
 Algos_1/utils.c  | 33 +++++++++++++++++++++++++++++++++
 Algos_1/utils.h  | 11 +++++++++++
 4 files changed, 50 insertions(+), 34 deletions(-)
 create mode 100644 Algos_1/utils.c
 create mode 100644 Algos_1/utils.h

diff --git a/Algos_1/main.c b/Algos_1/main.c
index b4d743e..2ded197 100644
--- a/Algos_1/main.c
+++ b/Algos_1/main.c
@@ -1,39 +1,8 @@
 #include "triInsertion.h"
 #include "triFusion.h"
 #include "triRapide.h"
+#include "utils.h"
 
-
-int readToTab(long* tab, char* file){
-    int n = 0;
-    int fd = open(file, O_RDONLY);
-    if(fd == -1){
-        perror("open");
-        exit(1);
-    }
-    char tmp[1000];
-    memset(tmp, 0, 1000);
-    char temp;
-    size_t j = 0, x=0;
-    read(fd,&temp,sizeof(char));
-
-    while(temp != '.'){
-        if(temp != ' '){
-            tmp[x] = temp;
-            x++;
-            
-        }
-        else if(temp == ' '){
-            long t = atol(tmp);
-            tab[j] = t;
-            memset(tmp, 0, 1000);
-            j++;
-            x=0;
-            n++;
-        }
-        read(fd,&temp,sizeof(char));
-    }
-    return n-1;
-}
 int main(int argc, char **argv){
     if(argc!=3){
         printf("Usage: ./tri <option> <input.txt>\n");
diff --git a/Algos_1/makefile b/Algos_1/makefile
index 6a8fd56..abccfb8 100644
--- a/Algos_1/makefile
+++ b/Algos_1/makefile
@@ -1,7 +1,7 @@
 all: tri
 
-tri: main.c triInsertion.o triFusion.o triRapide.o
-	gcc -Wall main.c triInsertion.o triFusion.o triRapide.o -Wall -o tri
+tri: main.c triInsertion.o triFusion.o triRapide.o utils.o
+	gcc -Wall main.c triInsertion.o triFusion.o triRapide.o utils.o -Wall -o tri
 
 insertion: triInsertion.c triInsertion.h
 	gcc -c triInsertion.c triInsertion.h -Wall
@@ -12,5 +12,8 @@ fusion: triFusion.c triFusion.h
 rapide: triRapide.c triRapide.h
 	gcc -c triRapide.c triRapide.h -Wall
 
+utils: utils.c utils.h
+	gcc -c utils.c utils.h -Wall
+
 clear:
 	rm *.o
\ No newline at end of file
diff --git a/Algos_1/utils.c b/Algos_1/utils.c
new file mode 100644
index 0000000..6ab7286
--- /dev/null
+++ b/Algos_1/utils.c
@@ -0,0 +1,33 @@
+#include "utils.h"
+
+int readToTab(long* tab, char* file){
+    int n = 0;
+    int fd = open(file, O_RDONLY);
+    if(fd == -1){
+        perror("open");
+        exit(1);
+    }
+    char tmp[1000];
+    memset(tmp, 0, 1000);
+    char temp;
+    size_t j = 0, x=0;
+    read(fd,&temp,sizeof(char));
+
+    while(temp != '.'){
+        if(temp != ' '){
+            tmp[x] = temp;
+            x++;
+            
+        }
+        else if(temp == ' '){
+            long t = atol(tmp);
+            tab[j] = t;
+            memset(tmp, 0, 1000);
+            j++;
+            x=0;
+            n++;
+        }
+        read(fd,&temp,sizeof(char));
+    }
+    return n-1;
+}
\ No newline at end of file
diff --git a/Algos_1/utils.h b/Algos_1/utils.h
new file mode 100644
index 0000000..18fe287
--- /dev/null
+++ b/Algos_1/utils.h
@@ -0,0 +1,11 @@
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+int readToTab(long* tab, char* file);
\ No newline at end of file
-- 
GitLab