Q: stack dump using alloc I seem to be getting a stack dump in my function where I am allocating memory.
I am passing an array of pointers '**output' to my function. And then I allocate enough memory to assign into that memory a string. However, I am getting a stack dump.
Many thanks for any suggestions,
void display_names(char **names_to_display, char **output);

int main(void)
{
    char *names[] = {"Luke", "John", "Peter", 0};
    char **my_names = names;
    char **new_output = 0;

    while(*my_names)
    {
        printf("Name: %s\n", *my_names++);
    }

    my_names = names; /* Reset */
    display_names(my_names, new_output);

    // Display new output
    while(*new_output)
    {
        printf("Full names: %s\n", *new_output++);
    }

    getchar();

    return 0;
}

void display_names(char **names_to_display, char **output)
{
    while(*names_to_display)
    {   
        // Stack dump here
        *output = (char*) malloc(sizeof("FullName: ") + strlen(*names_to_display)); // Allocate memory

        // Copy new output
        sprintf(*output, "FullName: %s", *names_to_display++);
        printf("display_names(): Name: %s\n", *output++);
    }   
}

======================== Updated ========================
void display_names(char **names_to_display, char **output);

int main(void)
{
    char *names[] = {"Luke", "John", "Peter", 0};
    char **my_names = names;
    char *new_output[] = {0};
    size_t i = 0;

    while(*my_names)
    {
        printf("Name: %s\n", *my_names++);
    }

    my_names = names; /* Reset */
    display_names(my_names, new_output);

    // Stack dump here.
    while(*new_output[i])
    {
        printf("Full names: %s\n", *new_output[i]);
        i++;
    }

    getchar();

    return 0;
}

void display_names(char **names_to_display, char **output)
{
    while(*names_to_display)
    {   
        *output = malloc(strlen("FullName: ") + strlen(*names_to_display) + 1); // Allocate memory

        // Copy new output
        sprintf(*output, "FullName: %s", *names_to_display++);
        printf("display_names(): Name: %s\n", *output++);
    }   
}


A: You have numerous errors, but the main one is that you are passing aNULL pointer to display_names:
char **new_output = 0;   // null pointer
...
display_names(my_names, new_output);

display_names then dereferences it:
*output = (char*) malloc(sizeof("FullName: ") 
             + strlen(*names_to_display)); // Allocate memory

resulting in the creash.
In addition, the above allocation is not big enough - you want to add 1 for the end of string marker, and you never seem to initialise the allocated memory. Also, it is a bad habit to get into using sizeof on character strings - it will work in this instance, but you should always use strlen.

A: You can't evaluate *output because you've passed on a output = null (in the main, *******newoutput=0*).
You can fix it by testing how many strings you have and the greatest strlen of them and start by allocating chunk to output, before you enter your sprintf loop.
As a side comment, where do you free that chunk? Don't answer "but I'm exiting right after"... 
