473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i nt C, char*** array);

void main() {
unsigned char ***arr_scenes=N ULL;
int R = 15;
int C = 15;

arr_scenes = Memory2DStr(nsc enes,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_FAILU RE);
}
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_FAILU RE);
}
}
return array;
}
static
void MemoryFreeStr(i nt Col, char*** array) {
int i;
for (i = 0; i < 15; i++) {
free((*array)[i]);
}
free(*array);
}
Thanks,
Sheldon

Nov 17 '06 #1
2 1976
In <11************ **********@k70g 2000cwa.googleg roups.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(i nt C, char*** array);

void main() {
unsigned char ***arr_scenes=N ULL;
int R = 15;
int C = 15;

arr_scenes = Memory2DStr(nsc enes,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
1928
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
2352
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 write to the other pointer (*dest). Should I check if the *dest pointer is NULL or not before writing to it ? Should I realloc it before I write to it ? Should I free it if != NULL and
4
2667
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 can avoid problems with it in the future. If there are any references I should check out let me know. Full highlighted code at:
5
3678
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 == NULL ) return;
20
10763
by: spasmous | last post by:
main() { float * f; initialize_f(f); // ...use f for processing free(f); }
1
2325
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" void main() {
25
2505
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 some of those advices like following? a. keep the interface clean and clear (What does clean or clear mean and how to achieve that?). b. avoid using static variables in local function if possible. c. avoid using global variables for local function...
4
2506
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
1764
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, it's actually a shorter version of something more complex that i am doing. Anway the idea is that there's a func Test which takes a pointer to void argument, allocate some memory, set this memory with some cotent, assign the ptr to a void to the...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.