Je ne comprend pas mon erreur
bonjour ;
j'arrive pas à comprendre l'erreur :
Citation:
tab.c: In function ‘intialiserLeTableau’:
tab.c:10:12: warning: returning ‘int **’ from a function with incompatible return type ‘int *’ [-Wincompatible-pointer-types]
10 | return(*Tab);
| ~^~~~~
tab.c:27:37: warning: comparison of distinct pointer types lacks a cast
27 | for(compteur = (Tab) ; compteur < (Tab +(*max)) ; compteur++ )
| ^
tab.c:29:45: error: invalid operands to binary - (have ‘int *’ and ‘int ***’)
29 | printf("Tab[%d] : %d \t", compteur - Tab , (*compteur));
| ^
compilation terminated due to -Wfatal-errors.
La question :
Ecrire une fonction qui demande la taille d’un tableau d’entiers puis qui alloue ce tableau ;
Remplir ce tableau d’entiers aléatoires entre 0 et 100 ;
Afficher le tableau ;
J'ai fait cela
Code:
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
| #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int * intialiserLeTableau(int **Tab[], int *max )
{
printf("veuillez introduire la taille du tableau : ");
scanf("%d",max);
*Tab = calloc((*max) , sizeof(int));
return(*Tab);
}
int * remplirAlea(int **Tab[] , int *max )
{
int *compteur;
for(compteur = *Tab ; compteur < (Tab +(*max)) ; compteur++ )
{
*compteur = rand()%101;
}
return (Tab);
}
void * afficheTableau(int **Tab[],int *max )
{
int *compteur;
for(compteur = (Tab) ; compteur < (Tab +(*max)) ; compteur++ )
{
printf("Tab[%d] : %d \t", compteur - Tab , (*compteur));
}
printf("\n\n");
}
int main()
{
int *P, *max ;
P = intialiserLeTableau(P , &max ) ;
afficheTableau(P,&max);
P = remplirAlea(&P, &max);
afficheTableau(&P,&max);
return EXIT_SUCCESS ;
} |