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 55 56
| #include <stdio.h>
#include <stdlib.h>
/* La fonction decompose decompose un mot en voyelles et consonnes
entree :
- pointeur vers le mot a decomposer
- adresse de la chaine de voyelles
- adresse de la chaine de consonnes
*/
void decompose (char *src, char **voyelles, char **consonnes);
void decompose (char *src, char **voyelles, char **consonnes)
{
int indice_src = 0, indice_voyelles = 0, indice_consonnes = 0;
char caractere_courant = src[indice_src];
printf("BOUCLE\n");
while (caractere_courant != '\0')
{
printf("caractere_courant : %c, indice_src = %d, indice_voy = %d, indice_cons = %d\n", caractere_courant, indice_src, indice_voyelles, indice_consonnes);
if(caractere_courant == 'a' || caractere_courant == 'e' || caractere_courant == 'i' || caractere_courant == 'o' || caractere_courant == 'u' || caractere_courant == 'y')
{
*voyelles[indice_voyelles] = caractere_courant;
indice_voyelles ++;
}
else
{
*consonnes[indice_consonnes] = caractere_courant;
indice_consonnes ++;
}
indice_src ++;
caractere_courant = src[indice_src];
}
printf("FIN BOUCLE\ncaractere_courant : %c, indice_src = %d, indice_voy = %d, indice_cons = %d\n", caractere_courant, indice_src, indice_voyelles, indice_consonnes);
*voyelles[indice_voyelles] = '\0';
*consonnes[indice_consonnes] = '\0';
}
main()
{
char *voyelles_mot, *consonnes_mot, *mot = "these";
voyelles_mot = (char*) malloc(10 * sizeof(char));
consonnes_mot = (char*) malloc(10 * sizeof(char));
decompose(mot, &voyelles_mot, &consonnes_mot);
printf("mot : %s\nvoyelles : %s\nconsonnes : %s\n", mot, voyelles_mot, consonnes_mot);
free(voyelles_mot);
free(consonnes_mot);
} |
Partager