I have such a function in C:
char **collect_character_distribution(char *buffer, long lSize)
{
printf("Collecting character distribution...\n");
long x;
char distribution[256][2] = {0};
for (x = 0; x < lSize; x++)
{
distribution[(int)buffer[x]][0] = (char) buffer[x];
distribution[(int)buffer[x]][1]++;
}
return (char **) distribution;
}
I need to return two dimensional distribution array from the function above. And my main function is as the following:
int main()
{
char *buffer;
long lSize;
struct Bar result = funct();
char **distribution;
buffer = result.x;
lSize = result.y;
distribution = collect_character_distribution(buffer, lSize);
printf("%s\n", distribution);
//struct Bar encoding_tree = generate_encoding_tree(distribution);
return 0;
}
I get the following error:
warning: function returns address of local variable [-Wreturn-local-addr]
How can I fix this problem?