Variable

cs_AngeloVivaldi Messages postés 60 Date d'inscription dimanche 8 décembre 2002 Statut Membre Dernière intervention 1 juillet 2004 - 7 mai 2003 à 04:05
cs_Kaid Messages postés 949 Date d'inscription mardi 2 octobre 2001 Statut Membre Dernière intervention 8 juillet 2006 - 7 mai 2003 à 11:22
Je voudrai utiliser un tableau mais je ne connais pas sa valeur pendant que je programme j'ai essayer un truk comme :

int size;

char tab[size];

mais sa marche pas ... quelqu'un n'aurai pas une idée ?

merci

4 réponses

crocejf2000 Messages postés 260 Date d'inscription lundi 27 janvier 2003 Statut Membre Dernière intervention 27 août 2008 1
7 mai 2003 à 07:58
char * tab;
Hart
0
highcobra Messages postés 122 Date d'inscription lundi 31 mars 2003 Statut Membre Dernière intervention 20 avril 2005
7 mai 2003 à 09:16
char * tab ;
ou
char tab[] ;
(c'est la même chose)
et après tu fait un calloc pour allouer ton tableau en mémoire dynamique...

High_Cobra ;)
0
cmarsc Messages postés 455 Date d'inscription mercredi 6 mars 2002 Statut Membre Dernière intervention 18 décembre 2003
7 mai 2003 à 10:38
<stdlib.h> malloc realloc calloc
0
cs_Kaid Messages postés 949 Date d'inscription mardi 2 octobre 2001 Statut Membre Dernière intervention 8 juillet 2006 1
7 mai 2003 à 11:22
Pour être complet sur l'allocation dynamique.

Allocation dynamique en C:

int SIZE=...;
// sizeof(char) est superflu ici mais c'est une bonne habitude à prendre
char* tab=(char*)malloc(SIZE * sizeof(char));

// Libération de la mémoire
free(tab);

Allocation dynamique en C++:

int SIZE=...;
char* tab=new char[SIZE];

// Libération de la mémoire
delete [] tab;

Kaid - kaid.fr.st
0
Rejoignez-nous