Bonjour tout le monde,

j'ai du mal � voir comment faire un tableau dynamique de string.

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 une erreur de segmentation quand la fonction est de ce type.

J'ai essayer autre chose :

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 le mot suivant : attention : address of local variable �tabSeq� returned

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