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
|
main()
{
int ch=2;
int *w;
int k=0,j;
int cpt=0;
void *p;
printf("la saisie:\n");
int sidouble_existe(int *tab,int val)
{
int existe_double=0,i=0;
while (existe_double==0 && i<strlen(tab))
{
if (*(tab+i)==val)
{existe_double=1;}
else { i++; existe_double=0;}
//printf("existe double est :%d", existe_double);
}
return existe_double;
}
w=(int*)malloc(sizeof(int));// si on l'enleve programme va cesser de fonctionner
do
{
//fflush(stdin);
printf("Entrez un chiffre:\n");
scanf("%d",&ch);
if (sidouble_existe(w,ch)==0)
{
cpt++;
if (p=(int*)realloc(w,sizeof(int)))
{
w=p;//la réallocation s est bien passe
*(w+k)=ch;
k++;
}
}
else {
printf("Vous avez saisi une valeur qui existe dèja");
}
}while(cpt<5);//par ex
//printf("les elements du tableau sont:\n%d",*w);
getch();
} |
Partager