Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1928 connectés 

  FORUM HardWare.fr
  Programmation

  [c] help me!!!

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[c] help me!!!

n°66512
magot
Posté le 19-10-2001 à 21:01:10  profilanswer
 

Bon alors voila, la fc qui suit doit permetre de rentrer un certain nombre de valeurs au clavier et les stocker en tant que char dans un tableau 2D or il y a un autre tableau contenant la longueur de chaque chaine. Ce dernier me pose beaucoup de pb et lorsque j'execute le prog cela plante sur l'instruction "tab_leng[i]=k;" au bout du troisieme tour de boucle
Pourquoi?????
 
 
voici le prog :
 
 
char** saisir_donnees( char **tab, int *nbelt, int *tab_leng, int *tab_adr)
{
 int i=0,j=0,ok=1,k=0,leng=0;
 char val[NBMAX]={0};
 
 free(tab);
 free(tab_leng);
 tab_leng=NULL;
 tab=NULL;
 while(ok)
 {
  fflush(stdin);
  printf("\nRentrer une valeur (taper f pour quitter) : \n" );
  gets(val);
  if( (val[0] == 'f';) || (val[0] == 'F';) )
   ok=0;
  else
  {
   j=0;
   leng=strlen(val);
   for(j=0;j<leng;j++)
   {
    if(val[j]<48 || val[j]>57)
    {
     if(val[j]!=45)
     {
      printf("ce n'est pas une valeur correcte!" );
      break;
     }
    }
   }
   if( (tab = (char**)realloc(tab,(i+1)*sizeof(char*))) == NULL )  
   {
    printf("Probleme d'allocation" );
    break;
   }
   if( (tab[i] = (char*)malloc(leng*sizeof(char))) == NULL )
   {
    printf("Probleme d'allocation" );
    break;
   }
   k=0;
   for(k=0;k<leng;k++)
    tab[i][k]=val[k];
   if( (tab_leng=(int*)realloc(tab_leng, (j+1)*sizeof(int))) == NULL )
   {
    printf("probleme d'allocation" );
    break;
   }
   tab_leng[i]=k;
   i++;
  }
 }  
 *nbelt=i;
 *tab_adr=(int)tab_leng;
 return(tab);
}

mood
Publicité
Posté le 19-10-2001 à 21:01:10  profilanswer
 

n°66548
gilou
Modérateur
Modzilla
Posté le 20-10-2001 à 04:18:02  profilanswer
 

if( (tab_leng=(int*)realloc(tab_leng, (j+1)*sizeof(int))) == NULL )
 
Tu voulais probablement ecrire  
 if( (tab_leng=(int*)realloc(tab_leng, (i+1)*sizeof(int))) == NULL )
 
A+,


---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [c] help me!!!

 

Sujets relatifs
[HTML/JAVASCRIPT] c tout con mais je sais plus... HELPhelp
Je voudrais un mot de passe pour une page web ! helpprobleme d' ASP...please help Urgent!!!!!
Help DLLHelp !!!
Afficher un document xml via page asp...please help[C++] Code pour compresser une image, ça marche pas... Help please
[DELPHI] Champ agregat HELP!!!Pros de Netscape, Help please....!!!
Plus de sujets relatifs à : [c] help me!!!


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR