Well first of all, learning how to indent code properly would significantly aid in clarity (both for you and us).
Code:
char **EtatsAccess(Automate * automate)
{
char **TabEtatAccess = malloc(sizeof(**TabEtatAccess));
int nbEtatAccess = 0;
int i = 0; //i c'est l'element en cours
TabEtatAccess[nbEtatAccess] = automate->EtatInit;
//char *chaine=automate->EtatInit;
nbEtatAccess++;
if (automate->tab_transition == NULL) {
exit(EXIT_FAILURE);
}
while (i < nbEtatAccess) {
Instruction *actuel = automate->tab_transition->premier;
while (actuel != NULL) {
if (strcmp(TabEtatAccess[i], actuel->etatInit.nom) == 0) {
//vérifier si cet elem n'existe pas
BOOLEAN exist = 0;
int i1 = 0;
for (i1 = 0; i1 < nbEtatAccess; i1++) {
if (strcmp(TabEtatAccess[i1], actuel->etatFin.nom) == 0) {
exist = 1;
break;
}
}
//Ajouter cet element
if (!exist) {
TabEtatAccess[nbEtatAccess] = actuel->etatFin.nom;
actuel->etatFin.esAccess = 1;
nbEtatAccess++;
}
}
actuel = actuel->suivant;
}
i++;
}
AffichEtatAccess(TabEtatAccess, nbEtatAccess);
automate->nbEtatAccess = nbEtatAccess;
return TabEtatAccess;
}
Next, you need to learn how to use malloc properly.
> char **TabEtatAccess = malloc(sizeof(**TabEtatAccess));
Every * in the declaration needs it's own independent malloc call. You can't allocate a ** variable in a single malloc call.
So for example,
Code:
char **TabEtatAccess;
TabEtatAccess = malloc( numberOfRows * sizeof(*TabEtatAccess) );
for ( i = 0 ; i < numberOfRows ; i++ )
TabEtatAccess[i] = malloc( numberOfCols * sizeof(*TabEtatAccess[i]) );
// This is the malloc equivalent of
// char TabEtatAccess[numberOfRows][numberOfCols]
Also notice the use of sizeof in this code. Using the form p = malloc( sizeof(*p) ); saves you from having to check back at the declaration to get the type right.
> TabEtatAccess[nbEtatAccess] = actuel->etatFin.nom;
You might want to think hard about what you're doing here.
It looks like you're going to end up with two pointers in two different data structures pointing at the SAME bit of memory.
If one of those data structures is deallocated, the other could end up with garbage pointers.
For safety, you should really make a copy of the string using strcpy() - remembering to make sure you have enough memory allocated.