From 5d053853a15e59dc1e6cf1549c61be8c8d9c6da4 Mon Sep 17 00:00:00 2001
From: j-twite <jonathan.twite@student.uclouvain.be>
Date: Tue, 14 Apr 2020 15:54:18 +0200
Subject: [PATCH] update

---
 Makefile       | 26 +++++++++++++++++++++++++-
 fileFeatures.h | 15 +++++++++++----
 prime_divs.c   |  6 +++---
 prime_divs.py  |  1 +
 4 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 5692993..75d42c6 100644
--- a/Makefile
+++ b/Makefile
@@ -1 +1,25 @@
-# Makefile
\ No newline at end of file
+# Makefile
+all:
+
+# Compile the program and \
+  build "fact" executable file.
+fact: prime_divs.c
+	  gcc -o fact prime_divs.c
+
+
+
+# make test compile votre programme \
+  et exécute les tests unitaires.
+test: #UnitTestFile
+	 #make fact
+	  #./UnitTestFile
+
+# clean the file directory, delete: \
+- fact executable (if present) \
+- auxiliary files built by \
+  fact & test commands.
+clean: fact
+	rm -rf *o fact
+	rm -rf *o test
+
+
diff --git a/fileFeatures.h b/fileFeatures.h
index bd9b457..f2823fa 100644
--- a/fileFeatures.h
+++ b/fileFeatures.h
@@ -21,6 +21,7 @@ int ipow(int base, int exp);
 // iterate through a mapped file and write each number found and factorize them
 // the program stop if file_in_memory contains anything else than a digit or a '\n'
 int factorize(char *file_in_memory, FILE *fileOutput) {
+    int line = 1;
     int start = 0;
     int size = strlen(file_in_memory);
     int i = 0;
@@ -29,12 +30,19 @@ int factorize(char *file_in_memory, FILE *fileOutput) {
             int k = 0;
             for (int j = i - 1; j >= start; j--)        // iterate from right to left
                 k += ((file_in_memory[j] - '0') *ipow(10, i - j - 1)); // record each digit into k
-            factAndWrite(fileOutput, k);                // write and factorize k into fileOutput
+            
+            if(k < 2)
+                printf("Entier plus petit que 2 (line %d): %d\n", line, k);
+            else 
+            factAndWrite(fileOutput, k);      // write and factorize k in fileOutput
             start = i += 1;
+            line ++;
         }
         else if ((file_in_memory[i] > '9' || file_in_memory[i] < '0') && file_in_memory[i] != '\n') {
-            perror("Not a digit.");
-            return -2;
+            printf("Entier mal formatté (line %d): %c.\n", line, file_in_memory[i]);
+            while(file_in_memory[i]!= '\n')
+                i++;
+        line++;
         }
         else
             i++;
@@ -76,4 +84,3 @@ int ipow(int base, int exp) {
 }
 
 #endif //PROJET_Q4_GROUPE_O4_FILEFEATURES_H
-
diff --git a/prime_divs.c b/prime_divs.c
index 129ec9b..2491961 100644
--- a/prime_divs.c
+++ b/prime_divs.c
@@ -16,8 +16,8 @@ int main(int argc, char *argv[])
     struct timeval stop, start;
     gettimeofday(&start, NULL);
 
-    printf("argv[1]: %s\n", argv[1]); // argv[1] = input file path
-    printf("argv[2]: %s\n", argv[2]); // argv[2] = output file path
+    printf("file input: %s\n", argv[1]); // argv[1] = input file path
+    printf("file output: %s\n", argv[2]); // argv[2] = output file path
 
     //open the fileInput
     int fileInput = open(argv[1], O_RDONLY);
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
 
     // print out the computation performance
     gettimeofday(&stop, NULL);
-    printf("%s factorized into %s.\ntook %lu µs\n", argv[1], argv[2], (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec);
+    printf("SUCCES.\ntook %lu µs\n", (stop.tv_sec - start.tv_sec) * 1000000 + stop.tv_usec - start.tv_usec);
 
     return 0;
 }
diff --git a/prime_divs.py b/prime_divs.py
index bf8ae88..1df36ba 100644
--- a/prime_divs.py
+++ b/prime_divs.py
@@ -109,3 +109,4 @@ if __name__ == '__main__':
 	logger.info("Fermeture des fichiers")
 	input_file.close()
 	output_file.close()
+
-- 
GitLab