#Why isn't my 2D Pointer/Array being passed down to the main method?

10 messages · Page 1 of 1 (latest)

pure meteorBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

steep comet
#
int getCharacters(char** aroar)
{
    char input[100];
    int counter = 0;
    while (scanf("%s", input) != EOF)
    {
        counter++;
        aroar = realloc(aroar, counter * sizeof(char*));
        if (aroar == NULL) {
            printf("Error: memory allocation failed.\n");
            exit(1);
        }

        aroar[counter - 1] = malloc((strlen(input) + 1) * sizeof(char));
        if (aroar[counter - 1] == NULL) {
            printf("Error: memory allocation failed.\n");
            exit(1);
        }
        strcpy(aroar[counter - 1], input);

    }
    for (int i = 0; i < counter; i++) {
        printf("%s\n", aroar[i]);
    }
    printf("%s", aroar[2]);

    return counter;
}
#

That is the code

#

This is what I wrote on console

#

I'm new to C so sorry if it's a dummy question

empty minnow
#

You're using pointer-to-pointer wrong.

steep comet
#

thanks

pure meteorBOT
#

@steep comet Has your question been resolved? If so, run !solved :)

pure meteorBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.