In a generic formulation, I have a function that places a value in an array of strings; just as an example:
char **matrizExemplo()
{
char **vet;
char tamVetor = 1;
vet = malloc(sizeof(char*)*tamVetor);
vet[0] = malloc(sizeof(char*)*10);
strcpy(vet[0], "teste");
printf("Dentro da funcao vet[0] e %s\n", vet[0]);
return vet;
}
int main()
{
char **retorno;
retorno = matrizExemplo();
printf("Retorno e: %s\n", retorno[0]);
return 0;
}
I can print the vet [0] inside the function, but when I execute segmentation fault, where am I wrong?