Add strcmp

This commit is contained in:
flyingscorpio@arch-desktop 2021-11-14 23:32:13 +01:00
parent 6abc10a6c4
commit a1c01f71ac
2 changed files with 60 additions and 0 deletions

1
.gitignore vendored
View file

@ -32,3 +32,4 @@ carte-identite
conversion-majuscule
mirroir
creation-mot-de-passe
strcmp

View file

@ -0,0 +1,59 @@
/* strcmp */
#include <stdio.h>
#include <stdlib.h>
int strcompare(char*, char*);
void get_alphabetical_order(char*, char*);
int main() {
char mot[100];
char *temoin = "CODEUR";
int i = 0;
printf("Ecrire un mot en majuscule : ");
fgets(mot, 100, stdin);
while (mot[i] != '\n') i++;
mot[i] = '\0';
if (strcompare(mot, temoin)) {
printf("Les mots sont identiques\n");
} else {
get_alphabetical_order(mot, temoin);
}
return 0;
}
int strcompare(char *mot1, char *mot2) {
int i = 0;
while (mot2[i] != '\0') {
if (mot1[i] != mot2[i]) {
return 0;
}
i++;
}
return 1;
}
void get_alphabetical_order(char *mot1, char *mot2) {
int i = 0;
while (1) {
if ((mot1[i] == '\0') || (mot2[i] == '\0')) {
break;
}
if (mot1[i] < mot2[i]) {
printf("%s > %s\n", mot1, mot2);
break;
}
if (mot1[i] > mot2[i]) {
printf("%s > %s\n", mot2, mot1);
break;
}
i++;
}
}