Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

function for allocating memory for string array

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


shejo284 at gmail

Nov 17, 2006, 6:14 AM

Post #1 of 3 (126 views)
Permalink
function for allocating memory for string array

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

--
http://mail.python.org/mailman/listinfo/python-list


bj_666 at gmx

Nov 17, 2006, 7:02 AM

Post #2 of 3 (120 views)
Permalink
Re: function for allocating memory for string array [In reply to]

In <1163772870.781423.161550 [at] k70g2000cwa>, 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
--
http://mail.python.org/mailman/listinfo/python-list


gagsl-py at yahoo

Nov 17, 2006, 4:49 PM

Post #3 of 3 (117 views)
Permalink
Re: function for allocating memory for string array [In reply to]

At Friday 17/11/2006 11:14, Sheldon wrote:

>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

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.