Passer un tableau à 2 dimension

cs_tintin72 Messages postés 122 Date d'inscription mercredi 16 avril 2003 Statut Membre Dernière intervention 22 juillet 2006 - 17 juin 2005 à 17:13
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 - 18 juin 2005 à 11:58
Bonjour,
Je voudrais savoir comment écrire une fonction qui prend en paramètre un tableau à 2 dimension, et comment lui passer un tableau à 2 dimension.

Merci
Tintin 72

8 réponses

vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
17 juin 2005 à 17:29
void f(int** tab)
{
tab[2][3] = 0;
}

// appel:
int** tab = new int[10];for(int i 0; i < 10; i++) tab[i] new int[20];
...
f(tab);

L'idéal est de passer aussi à f la dimention des tableaux (10 et 20 ici)
0
cs_tintin72 Messages postés 122 Date d'inscription mercredi 16 avril 2003 Statut Membre Dernière intervention 22 juillet 2006
17 juin 2005 à 18:02
Apparement y a un pb.
Voilà en gros ce que je voudrai faire

void fn(char** tab)
{
strcpy(tab[0], "Bonjour");
//etc...
}

char **chaine = new char[4];for(int i 0; i < 4; i++) chaine[i] new char[20];
...
fn(chaine);

mais le compilo me dit : cannot convert char* to char** in initialization

Tintin 72
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
17 juin 2005 à 18:18
Désolé, c'est



char **chaine = new char*[4];
0
cs_tintin72 Messages postés 122 Date d'inscription mercredi 16 avril 2003 Statut Membre Dernière intervention 22 juillet 2006
17 juin 2005 à 18:46
Ok, ça marche maintenant, merci.

Tintin 72
0

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

Posez votre question
cs_tintin72 Messages postés 122 Date d'inscription mercredi 16 avril 2003 Statut Membre Dernière intervention 22 juillet 2006
17 juin 2005 à 18:47
Je voudrais savoir si on peut faire la même chose en initialisant le tableau comme ça : char tab[5][50];
ce qui est qd même + rapide
Merci

Tintin 72
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
17 juin 2005 à 19:20
Oui ca doit se faire
0
cs_tintin72 Messages postés 122 Date d'inscription mercredi 16 avril 2003 Statut Membre Dernière intervention 22 juillet 2006
17 juin 2005 à 19:32
Oui mais comment ?
J'ai essayé mais le compilo dit : cannot convert char**[*][50] to char** for argument 1 to void fn(char**)
C quoi le pb?

Tintin 72
0
cs_Joky Messages postés 1787 Date d'inscription lundi 22 novembre 2004 Statut Membre Dernière intervention 31 janvier 2009 2
18 juin 2005 à 11:58
Purée si comme dis BruNews tout les new ça consomme, on est mal barré en faite ???
Y'a pas une solution plus souple lol ? :)


void Aurevoir( void ); //Bonne journée
0
Rejoignez-nous