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
| #include <stdlib.h>
#include <stdio.h>
#include <string.h>
void comptage (const char tab[], int * const pVoy, int * const pCons,const int len) // le parametre const permet de dire au compilateur
{ //la modification des caractères de tab.
int i; //si tu modifies la chaîne dans la fonction,
for(i=0; i< len; i++) //le compilateur emettra une erreur.
{
if(tab[i] == 'a' || tab[i] == 'e' || tab[i] == 'i' || tab[i] == 'o' || tab[i] == 'u' || tab[i] == 'y' )
(*pVoy)++;
else
(*pCons)++;
}
}
int main(int argc, char *argv[])
{
char tab[90];
int nbVoy = 0, nbCons = 0;
int *pVoy = &nbVoy; // Solution 2: Supprimmer ces deux lignes.
int *pCons = &nbCons;
int len=0;
puts("Entrez une phrase");
fgets(tab, sizeof tab, stdin);
printf("Vous avez entre: ");
puts(tab);
len = strlen(tab) ;
comptage(tab, pVoy, pCons,len); // Mettre ici comptage(tab, &nbVoy, &nbCons);
printf("Dans votre phrase, il y a %d voyelles\n", *pVoy); // Soit *pVoy soit nbVoy car: *pVoy = nbVoy
printf("Dans votre phrase, il y a %d consonnes\n", nbCons);
system("pause");
} |
Partager