Memory allocating/deallocating using functions

S

Sheldon

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 = 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));
}
free(*array);

}

Thanks,
Sheldon
 
R

Richard Tobin

Sheldon said:
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
 
R

Richard Heathfield

Sheldon said:
Hi,

Can someone tell me how to remove the conflicts here ?

#include <stdlib>

Start by making this said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top