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>
int parcours( void * tableau , size_t nb_elt , size_t taille, void * Ref)
{
int cmp = 0;
char * Elem = Ref;
char * tab = tableau;
size_t i;
for(i = 0 ; i < nb_elt ; i++)
{
if(*(tab + i * taille) == * Elem)
{
cmp++;
}
}
return cmp;
}
int main( void )
{
int X;
char Elem;
char tabi[10] = {'a','b','c','d','a','d','a','a','e','a'};
printf("Quel chiffre voulez-vous rechercher ?");
scanf("%s", &Elem);
X = parcours(tabi, sizeof(tabi)/sizeof(*tabi), sizeof(*tabi), Elem);
printf("il y a : %d ", X);
return EXIT_SUCCESS;
} |