Skip to content
Snippets Groups Projects
Commit 7adcfe42 authored by dario.genga's avatar dario.genga
Browse files

Add ex1

parent 260d24e7
No related branches found
No related tags found
No related merge requests found
# 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
/* 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;
}
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
makefile 0 → 100644
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment