Skip to content
Snippets Groups Projects
Commit ad38d800 authored by Florian Burgener's avatar Florian Burgener
Browse files

Validation exercice 1

parent f3940e21
No related branches found
No related tags found
No related merge requests found
/** /**
* @file main.c * @file main.c
* @author Prénom Nom * @author Florian Burgener
* @brief Exercice 1 * @brief Exercice 1
* @version 1.0 * @version 1.0
* @date 2021-12-07 * @date 2021-12-07
...@@ -9,31 +9,32 @@ ...@@ -9,31 +9,32 @@
* *
*/ */
#include <math.h> #include <ctype.h>
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
int main() { int main() {
char str1[100]; // 80 characters + 1 (null character).
char str2[100]; char str1[81];
char str2[81];
scanf("%s", str1); scanf("%s", str1);
scanf("%s", str2); scanf("%s", str2);
printf("%s\n", str1);
if (strlen(str1) != strlen(str2)) { if (strlen(str1) != strlen(str2)) {
// Strings do not have the same length.
printf("\ndistance: -1\n"); printf("\ndistance: -1\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int32_t distance = 0; int32_t distance = 0;
// Calculation of the distance.
for (int32_t i = 0; i < (int32_t)strlen(str1); i += 1) { for (int32_t i = 0; i < (int32_t)strlen(str1); i += 1) {
distance += abs(toupper(str1[i]) - toupper(str2[i])); distance += abs(toupper(str1[i]) - toupper(str2[i]));
} }
printf("\ndistance: %d\n", distance); printf("\ndistance: %d\n", distance);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment