I tried to get this to work for several hours, but it seems like I can't think of it.
I am trying to write a function that can return an array of strings.
#include <stdio.h>
#include <stdlib.h>
int FillArray( char *** Data );
int main()
{
char ** Data;
FillArray( &Data );
printf( "%s\n", Data[0] );
printf( "%s\n", Data[1] );
return EXIT_SUCCESS;
}
int FillArray( char *** Data )
{
*Data = malloc( sizeof(char*) * 2 );
char * Hello = "hello\0";
char * Goodbye = "goodbye\0";
Data[0] = &Hello;
Data[1] = &Goodbye;
return EXIT_SUCCESS;
}
I am probably confused with pointers somewhere because I get the following output:
hi
segmentation error
source
share