Witam,
Mam problem z funkcją która zwalnia pamięć dla tablicy wskaźników typu char. Był bym wdzięczny jak by ktoś udzielił mi jakiś wskazówek gdzie robię błąd.
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#define MAX 6
char** allocatePointerTable(int number);
char** deallocateTable(char **table);
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
char **options = NULL;
options = allocatePointerTable(MAX); //Alokuje pamięć dla tablicy wsk.
options[0] = "text0\n"; //Wypełniam tablice textem.
options[1] = "text1\n";
options[2] = "text2\n";
options[3] = "text3\n";
options[4] = "text4\n";
options[5] = "text5\n";
deallocateTable(options); //Próbuje usunąć tablice ale
//program się wysypuje.
getchar();
return 0;
}
//---------------------------------------------------------------------------
char** allocatePointerTable(int number)
{
char **pointerTable;
pointerTable = (char**)malloc(number * sizeof(char));
if(pointerTable == NULL)
{
printf("Nie udalo sie zaalokowac pamieci!\n");
exit(EXIT_FAILURE);
}
return pointerTable;
}
char** deallocateTable(char **table)
{
free(table);
table = NULL;
return table;
}