je cherche a faire un prog qui puisse agrandir un tableau de ptr:
 
Code :
 - #include <stdio.h>
 -  #define TAILLE 3
 -  void AjouterString(char*** p,const char* str)
 -  {
 -     int i=0;
 -     char **copy;
 -     copy=(char**)malloc((TAILLE+1));
 -     for(i=0;i<TAILLE;i++)
 -       copy[i] = (*p)[i];
 -     // free(*p);   //provoque un segmentation fault???
 -     copy[TAILLE]=(char*)str;
 -     *p=copy;
 - }
 -  void AfficherString(char** pStr)
 -  {
 -    int i=0;
 -    while(i<TAILLE+1)
 -      {
 -        printf("%s\n",pStr[i]);
 -        i++;
 -      }
 -  }
 -  int main()
 -  {
 -   char *pStr[]={"Une","chaine","bidon"};
 -   AjouterString(&pStr,"!" );
 -   AfficherString(pStr);
 -   return 0;
 - }
 
  | 
 
j'avais tester ce code avec un tableau de int* ça marchait, mais  avec des chaînes de caractères, l'affichage de la dernière chaine ne se fait pas (à la place j'ai des caractères bidons!), de plus je ne comprend pas pourquoi un free(*p) dans AjouterString provoque un segmentation fault
 
si quelqu'un voit le pbm....
 
Message édité par weblook$ le 26-11-2002 à 00:21:35