Bonjour tout le monde,
j'ai du mal à voir comment faire un tableau dynamique de string.
j'ai une erreur de segmentation quand la fonction est de ce type.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 string * buildTabSeq(int nbSeq, string totalSeq, int * tabLengthSeq){ //cout<<"buildTabSeq"<<endl; string * tabSeq=(string*)malloc(nbSeq*sizeof(new string[maxLengthSeq])); //string tabSeq [nbSeq]; int pos=0; for(int i=0; i<nbSeq; i++){ tabSeq[i]=totalSeq.substr(pos, tabLengthSeq[i]); cout<<i<<" "<<pos<<endl; //cout<<"substr : "<<tabSeq[i]<<endl; pos+=tabLengthSeq[i]; } return tabSeq; }
J'ai essayer autre chose :
j'ai le mot suivant : attention : address of local variable ‘tabSeq’ returned
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 string * buildTabSeq(int nbSeq, string totalSeq, int * tabLengthSeq){ //cout<<"buildTabSeq"<<endl; //string * tabSeq=(string*)malloc(nbSeq*sizeof(new string[maxLengthSeq])); string tabSeq [nbSeq]; int pos=0; for(int i=0; i<nbSeq; i++){ tabSeq[i]=totalSeq.substr(pos, tabLengthSeq[i]); cout<<i<<" "<<pos<<endl; //cout<<"substr : "<<tabSeq[i]<<endl; pos+=tabLengthSeq[i]; } return tabSeq; }
et quand j'affiche ce qu'il y a dans ma tableau j'ai des symboles bizarre.
Je vois pas comment faire. Et je ne peux pas faire de liste ou vecteur car le but est de pouvoir récupérer une valeur en fonction de l'index sans parcourir toute la liste ou vecteur.
Est ce que quelqu'un peut m'aider. C'est assez urgent en plus.
Alan
Partager