Hello,
I am working on a problem statement which typedefs an array like
Code:
typedef signed char Type[6]
the task is to create a function that will take input parameters as rows and cols and create a 2-dimensional pointer array of data type 'Type' having the number of rows and cols passed in as inputs. There is an additional requirement that all memory allocations should happen in only one call to malloc()
I tried this but don't think it is correct.
Can someone provide some pointers?
Code:
Type **testArray(size_t rows, size_t cols)
{
Type **temp = NULL;
temp = (Type **)malloc(rows * cols * sizeof(Type));
if (temp == NULL)
{
//error out
}
return temp;
}