Passage d'1 tableau 2D en paramêtre d'1 fonct

Résolu/Fermé
godzilla393 Messages postés 16 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 9 mai 2009 - 5 mai 2009 à 22:17
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 - 6 mai 2009 à 23:04
Bonjour,
J'ai défini la fonction suivante :
p_direction balayage (points position ,double cap ,int circ[NC][MC]) { ....}

avec
struct s_point {int abscisse;int ordonnee;};   
typedef  struct s_point* points;
struct s_direction { double s_teta; double s_dist_obst;};
typedef struct s_direction * p_direction;


j'utilise ma fonction comme suit :
p_direction d=  balayage ( p1, PI/2., circ[NC][MC]);


mais ce warning s'affiche:
warning: passing argument 3 of ‘balayage’ from incompatible pointer

Pourquoi? Comment y remédier?
Merci d'avance pour la réponse.
A voir également:

7 réponses

fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 835
6 mai 2009 à 23:04
Ah, voilà qui est intéressant. ^^.

circ[NC][MC]=circuit(N,M);
Ce n'est pas bon.

Pour les explications :
//création d'un tableau.
int circ[NC][MC];
//pour le remplir :
void circuit(int circ[][MC],int n, int m) {
   circ[i][j]=...
   //etc
}

//l'appel de la fonction
circuit(circ,n,m);


Si tu veux réaliser avec int **circuit. Cela n'est pas un tableau (en C, une fonction ne peut pas renvoyer de tableaux). Cela renvoie un pointeur sur la première case d'une zone mémoire allouée dans le heap.
int **circ=circuit(n,m);

int **circuit(int n, int m) {
    //allocation d'une zone avec malloc ou calloc
    ...
    return zone;
}

//Dans ce cas le prototype est effectivement :
p_direction balayage (  points position,double cap , int** circ);

//attention à ne pas oublier le free pour libérer la zone dans le heap.
1
hamed01 Messages postés 207 Date d'inscription lundi 30 juin 2008 Statut Membre Dernière intervention 22 juillet 2011 24
5 mai 2009 à 22:58
pourquoi pas:
p_direction d= balayage ( p1, PI/2, circ);

avec circ etant le tableau 2D
0
godzilla393 Messages postés 16 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 9 mai 2009 1
6 mai 2009 à 17:54
ca marche en tapant
p_direction balayage (  points position,double cap , int** circ) {  


et

balayage ( p1, 0., circ);


merci
0
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 835
6 mai 2009 à 21:39
Ca marche en tapant
Ca ne devrait pas marcher. Tu dois obtenir un warning. De plus, cela va te conduire à d'étranges problèmes au sein de la fonction puisque le compilateur ne saura pas la taille de la deuxième dimension.

Le bon prototype est :
p_direction balayage ( points position,double cap , int circ[][MC])

Et l'appel est : balayage ( p1, 0., circ);
Cdlt
0
godzilla393 Messages postés 16 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 9 mai 2009 1
6 mai 2009 à 21:48
bonjour, j'ai changé en int circ[][MC]
MC étant une macro donnant la 2eme dimension du tableau, n'est ce pas pour cela que int ** circ ne me déclenchait pas de warning?
Je ne comprends pas pourquoi ca fonctionne avec l''écriture int ** circ, que je trouvais d'ailleurs douteuse.

Merci pour votre éclairage à ce sujet.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
godzilla393 Messages postés 16 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 9 mai 2009 1
6 mai 2009 à 21:59
finalement en écrivant
int circ[][MC] dans la fonction puis : balayage ( p1, 0., circ);
j'obtiens tjs un warning !!
warning: passing argument 3 of ‘balayage’ from incompatible pointer type
0
fiddy Messages postés 11069 Date d'inscription samedi 5 mai 2007 Statut Contributeur Dernière intervention 23 avril 2022 1 835
6 mai 2009 à 22:45
Quelle est la déclaration de ton tableau circ ?
0
godzilla393 Messages postés 16 Date d'inscription mardi 5 mai 2009 Statut Membre Dernière intervention 9 mai 2009 1
6 mai 2009 à 22:49
c 'est à dire?
tu veux le détail du code?

circ[NC][MC]=circuit(N,M);

/* création de circuits */

int **circuit ( int n, int  m ) { ...
0