Problème de free() sur un char **
Salut à tous !
J'ai le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| void
historique ()
{
int nbLignes = 15;
char **historique;
int i;
historique = malloc (sizeof(char *) * nbLignes);
for (i = 0; i != nbLignes; i++)
{
historique[i] = malloc(sizeof(char*));
historique[i] = "abcdefabcdefabcdefabcdefabcdef"+i;
if (i >= 1 && historique[i] == NULL)
break;
}
for (i--; i >= 0; i--)
printf ("%s\n", historique[i]);
for (i=0; historique[i] != NULL; i++)
free(historique[i]);
free(historique);
} |
Le problème est que le [i]free(historique); ne passe pas :
Code:
** glibc detected *** monprog: free(): invalid pointer: 0x0000000000401858 ***
Pouvez-vous m'indiquer où est le problème ?