Skip to content
Extraits de code Groupes Projets
Valider 5d053853 rédigé par Jonathan Twite's avatar Jonathan Twite
Parcourir les fichiers

update

parent a237f8b2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #3373 réussi
# Makefile # Makefile
\ No newline at end of file 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
...@@ -21,6 +21,7 @@ int ipow(int base, int exp); ...@@ -21,6 +21,7 @@ int ipow(int base, int exp);
// iterate through a mapped file and write each number found and factorize them // 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' // 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 factorize(char *file_in_memory, FILE *fileOutput) {
int line = 1;
int start = 0; int start = 0;
int size = strlen(file_in_memory); int size = strlen(file_in_memory);
int i = 0; int i = 0;
...@@ -29,12 +30,19 @@ int factorize(char *file_in_memory, FILE *fileOutput) { ...@@ -29,12 +30,19 @@ int factorize(char *file_in_memory, FILE *fileOutput) {
int k = 0; int k = 0;
for (int j = i - 1; j >= start; j--) // iterate from right to left 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 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; start = i += 1;
line ++;
} }
else if ((file_in_memory[i] > '9' || file_in_memory[i] < '0') && file_in_memory[i] != '\n') { else if ((file_in_memory[i] > '9' || file_in_memory[i] < '0') && file_in_memory[i] != '\n') {
perror("Not a digit."); printf("Entier mal formatté (line %d): %c.\n", line, file_in_memory[i]);
return -2; while(file_in_memory[i]!= '\n')
i++;
line++;
} }
else else
i++; i++;
...@@ -76,4 +84,3 @@ int ipow(int base, int exp) { ...@@ -76,4 +84,3 @@ int ipow(int base, int exp) {
} }
#endif //PROJET_Q4_GROUPE_O4_FILEFEATURES_H #endif //PROJET_Q4_GROUPE_O4_FILEFEATURES_H
...@@ -16,8 +16,8 @@ int main(int argc, char *argv[]) ...@@ -16,8 +16,8 @@ int main(int argc, char *argv[])
struct timeval stop, start; struct timeval stop, start;
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
printf("argv[1]: %s\n", argv[1]); // argv[1] = input file path printf("file input: %s\n", argv[1]); // argv[1] = input file path
printf("argv[2]: %s\n", argv[2]); // argv[2] = output file path printf("file output: %s\n", argv[2]); // argv[2] = output file path
//open the fileInput //open the fileInput
int fileInput = open(argv[1], O_RDONLY); int fileInput = open(argv[1], O_RDONLY);
...@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) ...@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
// print out the computation performance // print out the computation performance
gettimeofday(&stop, NULL); 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; return 0;
} }
...@@ -109,3 +109,4 @@ if __name__ == '__main__': ...@@ -109,3 +109,4 @@ if __name__ == '__main__':
logger.info("Fermeture des fichiers") logger.info("Fermeture des fichiers")
input_file.close() input_file.close()
output_file.close() output_file.close()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter