I'm implementing a sliding puzzle program in C based on what the user inputs as their width of the slide (can only be 2, 3, 4). I feel like my syntax is correct for creating the 2D array (which is what we are using to represent the numbers in a later function), however, my function is not being called correctly. Instead it is hanging when I try to run it.
I cannot change the syntax of the function because it is a requirement that we have this in our program. So I'm wondering if it is a program passing in the function in main. I appreciate any help. Thank you.
int main() {
int w; /*variable asking for width*/
printf("Width: ");
scanf("%d\n", &w); /*&w will refer to make_tiles when function is called*/
make_tiles(w);
return 0;
}
int **make_tiles(int width) {
int **tiles;
int counter = 0;
int i, j;
tiles[i] = (int*) malloc(width*sizeof(int*));
for(i = 0; i < width; i++) {
for(j = 1; j < width; j++) {
tiles[i][j] = counter++;
printf(" %d", tiles[i][j]);
}
printf("\n");
}
}