473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

Nov 17 '06 #1
2 1961
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henrietta Denoue | last post by:
Hi I am new to C++ and suffering from dynamic allocation. I have a function that returns an integer pointer and want to assign this to another pointer: class cssReader { public:
7
by: George Marshall | last post by:
Hi all, my question is what should I do with a pointer to be used inside a function ? The following function should take a pointer to a null terminated array of chars, do something with it, and...
4
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I...
5
by: Johnathan Doe | last post by:
Why is is necessary to write a function that allocates memory for, or changes, a pointer to a char array using char** instead of char*? E.g. void modify_string( char** string ) { if( string...
20
by: spasmous | last post by:
main() { float * f; initialize_f(f); // ...use f for processing free(f); }
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
25
by: lovecreatesbeauty | last post by:
Could you talk something about the general rules on the interface (function) design in C program that recognized publically? Or introduce some good advice of yourself. How do you think about...
4
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
8
by: mast2as | last post by:
I almost apologize to ask this question but I have been starting at this code for a bit of time and don't understand what's wrong with it. I am not arguing about the fact it's good or not coding,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.