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

function for allocating memory for string array

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 <11**********************@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
Nov 17 '06 #2

P: n/a
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
Nov 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.