Memory allocating/deallocating using functions

  • Follow


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

0
Reply shejo284 (227) 11/17/2006 2:16:41 PM

In article <1163773001.360593.126270@h54g2000cwb.googlegroups.com>,
Sheldon <shejo284@gmail.com> wrote:

>Can someone tell me how to remove the conflicts here ?

I don't konw what you mean by "conflicts", but you could start by:

 - including <stdlib.h> instead of <stdlib>
 - include <stdio.h>
 - declaring main() properly
 - declaring nscenes
 - sorting out your "char ***" and "unsigned char ***"

and then you should consider what those unused R and C variables in
main are for.

Of course, you could have got all of that from reading your compiler's
error messages.

-- Richard
-- 
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
0
Reply richard91 (3683) 11/17/2006 2:27:41 PM


Sheldon said:

> Hi,
> 
> Can someone tell me how to remove the conflicts here ?
> 
> #include <stdlib>

Start by making this <stdlib.h> rather than <stdlib>

> static char*** Memory2DStr(int R, int C);
> static void MemoryFreeStr(int C, char*** array);
> 
> void main() {

Continue by getting the return type of main right.

When you've learned those two important lessons, come on back.

-- 
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not 
adjust your email clients.
0
Reply invalid171 (6556) 11/17/2006 2:32:31 PM

2 Replies
31 Views

(page loaded in 0.042 seconds)

Similiar Articles:













7/7/2012 9:42:22 PM


Reply: