diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..51efe3406b44db65904fbd38667438e64d00dfff --- /dev/null +++ b/.gitignore @@ -0,0 +1,81 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/c,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=c,visualstudiocode + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +!.vscode/*.code-snippets + +# End of https://www.toptal.com/developers/gitignore/api/c,visualstudiocode + +# Custom gitignore for project +main \ No newline at end of file diff --git a/ex1/main.c b/ex1/main.c new file mode 100644 index 0000000000000000000000000000000000000000..cd15dcf95bc40ce50227af0318ffb5281534ab49 --- /dev/null +++ b/ex1/main.c @@ -0,0 +1,41 @@ +/* Author : Dario GENGA + * Date : 07.12.2021 + * Description : ContrĂ´le continue 1 - Exercice 1 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#define MAX_WORD_LENGTH 80 + +int main() { + char *word1 = malloc(sizeof(char) * MAX_WORD_LENGTH); + char *word2 = malloc(sizeof(char) * MAX_WORD_LENGTH); + int distance = 0; + + // Get the word from the user + scanf("%s", word1); + scanf("%s", word2); + + if (strlen(word1) != strlen(word2)) { + // The words must have the same length + distance = -1; + } else { + // Compute the distance of each letters + for(size_t i = 0; i < strlen(word1); i++) { + int distance_tmp = tolower(word1[i]) - tolower(word2[i]); + if (distance_tmp < 0) { + distance_tmp = -distance_tmp; + } + distance += distance_tmp; + } + } + // Print the result and free the memory + printf("\ndistance : %d\n", distance); + + free(word1); + free(word2); + + return EXIT_SUCCESS; +} diff --git a/ex1/makefile b/ex1/makefile new file mode 100644 index 0000000000000000000000000000000000000000..a217aa28ef6b3524ffcef99d4b31e2d03e8b0cc4 --- /dev/null +++ b/ex1/makefile @@ -0,0 +1,10 @@ +LIB=-lm +CC=gcc -Wall -Wextra -pedantic -g + +main: main.o + $(CC) $^ -fsanitize=address -fsanitize=leak -o $@ $(LIB) + +main.o: main.c + $(CC) -c $< $(LIB) +clean: + rm -f *.o main \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000000000000000000000000000000000000..60750c72f1e5d83f75b10bcd6d7f7752937a5f96 --- /dev/null +++ b/makefile @@ -0,0 +1,18 @@ +LIB=-lm +CC=gcc -Wall -Wextra -pedantic -g + +matrix: matrix.o main.o + $(CC) $^ -fsanitize=address -fsanitize=leak -o $@ $(LIB) + +run_tests: tests + ./$< + +tests: test.o matrix.o + $(CC) $^ -fsanitize=address -fsanitize=leak -o $@ $(LIB) + +matrix.o: matrix.c matrix.h + $(CC) -c $< $(LIB) +main.o: main.c + $(CC) -c $< $(LIB) +clean: + rm -f *.o matrix tests \ No newline at end of file