0

I started to use the method taught by Lundin here to dynamically allocate multidimensional arrays in C in Codeblocks. Now I switched to Visual Studio 2017 and I can't do it anymore, and I don't know how to do it. I have read many questions and answers and I google searched for the answer, but I still can't do it. Please help me to dynamically allocate a 2D array in Visual Studio. Here is the my code:

#define _CRT_SECURE_NO_DEPRECATE
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
void arr_alloc(size_t x, size_t y, int(**aptr)[x][y])
{
    *aptr = malloc(sizeof(int[x][y])); // allocate a true 2D array
    assert(*aptr != NULL);
}

int main()
{
    int n = 5;

    int(*aptr)[n][n];
    arr_alloc(n, n, &aptr);

    return 0;
}

I will add a screenshot with the error messages and the code.enter image description here

Timʘtei
  • 753
  • 1
  • 8
  • 21

0 Answers0