function for allocating memory for string array

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
 
M

Marc 'BlackJack' Rintsch

Can someone tell me how to remove the conflicts here ?

What do you mean by conflicts? I see a bunch of undeclared functions
here. Just look at the compiler messages and fix the problems one by one.
#include <stdlib>

Here is missing a ``.h`` suffix.
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);

Where is `nscenes` coming from? And you should pay attention how the
types are declared. You assign `char ***` return value from
`Memory2DStr()` to `unsigned char ***` typed `arr_scenes`.
for (i = 0; i < C; i++) {
array = calloc(R,sizeof(char*));
if(array == NULL) { // Memory for the Col


C++ comments are not allowed in ANSI C. Some compilers understand them
but if you want to write portable code you should steer clear of them.
fprintf(stderr, "Failed to allocate memory\n");

The declaration of `fprintf()` lives in `stdio.h`.

Ciao,
Marc 'BlackJack' Rintsch
 
G

Gabriel Genellina

Can someone tell me how to remove the conflicts here ?

Wrong group!
Anyway, there is no need to reinvent the wheel, there are many array
libraries for C...


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 

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

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top