function for allocating memory for string array

Sheldon shejo284 at gmail.com
Fri Nov 17 15:14:30 CET 2006


Hi,

Can someone tell me how to remove the conflicts here ?

#include <stdlib>
static char*** Memory2DStr(int R, int C);
static void MemoryFreeStr(int C, char*** array);

void main() {
unsigned char ***arr_scenes=NULL;
int R = 15;
int C = 15;

arr_scenes = Memory2DStr(nscenes,2);
MemoryFreeStr(2,arr_scenes);
}
static
char*** Memory2DStr(int R, int C) {
  char*** array;
  int i;
  array = calloc(C,sizeof(char **));
  if(array == NULL) {
    fprintf(stderr, "Failed to allocate memory\n");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < C; i++) {
    array[i] = calloc(R,sizeof(char*));
    if(array == NULL) { // Memory for the Col
      fprintf(stderr, "Failed to allocate memory\n");
      exit(EXIT_FAILURE);
    }
  }
  return array;
}
static
void MemoryFreeStr(int Col, char*** array) {
  int i;
  for (i = 0; i < 15; i++) {
    free((*array)[i]);
  }
  free(*array);
}


Thanks,
Sheldon




More information about the Python-list mailing list