function for allocating memory for string array

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Nov 17 10:02:37 EST 2006


In <1163772870.781423.161550 at k70g2000cwa.googlegroups.com>, Sheldon wrote:

> 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[i] = 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



More information about the Python-list mailing list