Aug
11
Create an “empty” dynamic 2-D array?
August 11th, 2010 posted by
admin
Write a C function function create() that creates an “empty” dynamic 2-dimensional array with the number of rows given by its first argument (called rows) and the number of columns given by its second argument (called columns). If the value of ‘columns’ is < 1, then pretend that the value of 'columns' is 1, if the value of 'rows' is < 1, than pretend that the value of 'rows' is 1. The dynamic array is created using malloc() function and if an error during memory allocation occurs, the whole program (not just the function create()) must be terminated with an error message "memory allocation error". Leave the content of the array "undefined", i.e. leave the 'junk' there.


marshal_jed_cooper says:
August 13th, 2010 at 9:14 am
void** create(int rows, int cols, unsigned int size)
{
void** ptr ;
int i;
ptr = (void**)malloc(size*rows) ;
for (i=0; i