By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,344 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,344 IT Pros & Developers. It's quick & easy.

Memory allocating/deallocating using functions

P: n/a
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

Nov 17 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <11**********************@h54g2000cwb.googlegroups .com>,
Sheldon <sh******@gmail.comwrote:
>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.hinstead 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.
Nov 17 '06 #2

P: n/a
Sheldon said:
Hi,

Can someone tell me how to remove the conflicts here ?

#include <stdlib>
Start by making this <stdlib.hrather 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.
Nov 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.