diff --git a/Makefile b/Makefile index 5692993c4371a89034a00b406bfd1ea773f853c2..75d42c65da92c3866e4a469c301fbac881851e0d 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 bd9b457d78f80d2a183c219a359fad08cac27b35..f2823fa1b093138fc0901999dfcc20747ea922bc 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 129ec9b12825f9c1a70b385e8c173f73c19e2aec..2491961dfa077f0a9ebd1500832fb560f29c45a2 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 bf8ae880c0faf5b7742d57490deb6a68f9673e4a..1df36ba1b547403b55cc4f86614ce4f0303b1189 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() +