473,395 Members | 1,649 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,395 software developers and data experts.

Memory allocating/deallocating using functions

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 1374
In article <11**********************@h54g2000cwb.googlegroups .com>,
Sheldon <sh******@gmail.comwrote:
>Can someone tell me how to remove the conflicts here ?
I don't konw what you mean by "conflicts", but you could start by:

- including <stdlib.hinstead of <stdlib>
- include <stdio.h>
- declaring main() properly
- declaring nscenes
- sorting out your "char ***" and "unsigned char ***"

and then you should consider what those unused R and C variables in
main are for.

Of course, you could have got all of that from reading your compiler's
error messages.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 17 '06 #2
Sheldon said:
Hi,

Can someone tell me how to remove the conflicts here ?

#include <stdlib>
Start by making this <stdlib.hrather than <stdlib>
static char*** Memory2DStr(int R, int C);
static void MemoryFreeStr(int C, char*** array);

void main() {
Continue by getting the return type of main right.

When you've learned those two important lessons, come on back.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Greg Baker | last post by:
I don't know what standard protocol is in this newsgroup. Am I allowed to post code and ask for help? I hope so.. :) Here's my problem: I am trying problem 127 of the valladolid online...
4
by: trouble | last post by:
Hi, I have a program that needs to reserve about 1 to 10 Mb of memory every time it's run. Only one instance of the program is run at any given time but it's called about 100 times in...
2
by: DANIEL BEAULIEU J | last post by:
Basically i am a student taking an operating systems course which is c++ intensive. Familiar with Java, and so not so familiar with memory management. Looking for suggestions of exercises or web...
9
by: Andrew | last post by:
Hi all, with the following code snippet I am creating a 2D matrix : ....... double **retdouble=(double **)malloc(Y_dim*(sizeof(double *))); if(retdouble == NULL) { printf("Error Allocating...
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
7
by: toton | last post by:
Hi, I have a STL vector of of characters and the character class has a Boost array of points. The things are vector<Characterchars; and class Character{ private: array<Point,Npoints; }; Now...
1
by: Abubakar | last post by:
Hi, is there any win32 api or standard library function that would tell me how much memory my application/process is taking? What I want is to see how much memory some of my important functions...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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,...

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.