I read on some ways to dynamically create and use a 2D array, and I've settled on this way:

file:

```
5 4
+---+
|xxx|
|xxx|
+---+

```

main.c:

```c
char** loadArray() {
    FILE *in = fopen("file", "r");

    int w, h;
    fscanf(in, "%d %d\n", &w &h);

    char (*buf)[w] = malloc(sizeof(char[h][w]));

    for (int i = 0; i < h; i++) {
        fscanf(in, "%s\n", buf[i]);
    }

    fclose();

    return buf;
}

int main() {
    char** array = loadArray();
    for (int i = 0; i < 4; i++) { // magic number, only because I know the size
        printf("%s\n", array[i]);
    }
    return 0;
}

```

While this does compile, it gives a warning: `incompatible pointer types returning 'char (*)[w]' from a function with result type 'char **'`, and segfaults if I try to run it.

Several questions (mainly for C, but C++ specific answers are welcome for future reference, when I get there):

1. What is the correct return type for a multidimensional array? The warning isn't quite helpful I think, since it offers a variable term, which I obviously don't have until I read the file.
2. At this point, I'm just trying to get returning 2D arrays to work, but when I do and move on, I'm going to need the dimensions of the array for proper usage later on. My first idea would be to return structs instead, where I can save the dimension and the array itself. However, after further thought, the variable size makes me think that I wouldn't be able to have a single struct template to use as the function's return type, and I would have to find some other way to get the size along with the array. Are ideas?

Thank you for your time.