1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| const char *mot1 = "abcde";
const char *mot2 = "abcdz";
char *first = NULL;
char *second = NULL;
const char *max_length_word;
int i, min_length;
if ( (strlen(mot1)) > (strlen(mot2)) )
{
min_length = strlen(mot2);
max_length_word = mot1;
}
else if ( (strlen(mot1)) < (strlen(mot2)) )
{
min_length = strlen(mot1);
max_length_word = mot2;
}
else
{
min_length = strlen(mot1);
max_length_word = mot1;
}
for (i = 0; i < min_length; i++)
{
if (mot1[i] < mot2[i])
{
first = mot1;
second = mot2;
break;
}
else if (mot1[i] > mot2[i])
{
first = mot2;
second = mot1;
break;
}
else
continue;
}
/*
** Si la taille du mot1 est égale à la taille du mot2 et que le mot1 et égale au mot2 dans l'ordre alphabétique
** alors mot1 vient en premier dans l'ordre finale car il est le premier fourni.
*/
if (first == NULL)
{
first = max_length_word;
(first == mot1) ? (second=mot2) : (second=mot1);
} |
Partager