473,569 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calloc of "unsigned char my_bytes[256][256]"

See subject: how do I calloc (and free the memory, if that's not
free(my_bytes); ) this?

TIA!
Nov 13 '05 #1
43 3373


M-One wrote:
See subject: how do I calloc (and free the memory, if that's not
free(my_bytes); ) this?

TIA!


A good start on learning how would be to read the faq located at:
http://www.eskimo.com/~scs/C-faq/top.html

Question 6.16 discuss this topic.
http://www.eskimo.com/~scs/C-faq/q6.16.html
--
Al Bowers
Tampa, Fl USA
mailto: xa*@abowers.com base.com (remove the x)
http://www.geocities.com/abowers822/

Nov 13 '05 #2

M-One <sp***@uni-one.nl> wrote in message
news:3F******** *******@uni-one.nl...
See subject: how do I calloc (and free the memory, if that's not
free(my_bytes); ) this?


Have you tried looking up the documentation for calloc
and free?

#include <stdio.h>
#include <stdlib.h>

int main()
{
unsigned char *my_bytes = calloc(256 * 256, sizeof *my_bytes);
if(my_bytes == NULL)
{
fprintf(stderr, "Cannot allocate memory");
return EXIT_FAILURE;
}

/* whatever */

free(my_bytes);
return EXIT_SUCCESS;
}

-Mike

Nov 13 '05 #3
>> See subject: how do I calloc (and free the memory, if that's not
free(my_bytes); ) this?
Have you tried looking up the documentation for calloc
and free?


Yes; thanks for the example.
Nov 13 '05 #4
> Question 6.16 discuss this topic.
http://www.eskimo.com/~scs/C-faq/q6.16.html


Thanks for the pointer.
Nov 13 '05 #5
Al Bowers <xa*@abowers.co mbase.com> wrote in message
news:yg******** ********@news.r andori.com...
Al Bowers
Tampa, Fl USA


Hey Al, how does Lou's hair look? :-)

-Mike (Seattle, WA)


Nov 13 '05 #6
On Sun, 06 Jul 2003 14:26:30 GMT, Al Bowers <xa*@abowers.co mbase.com>
wrote:
M-One wrote:
> Question 6.16 discuss this topic.
> http://www.eskimo.com/~scs/C-faq/q6.16.html

[...]
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for

#define NROWS 256
#define NCOLUMNS 256
typedef struct ARRAY{
unsigned char **array1;
size_t nrows;
size_t ncolumns;
}ARRAY;
int resizeARRAY(ARR AY *p, size_t nrows, size_t ncolumns);
void freeARRAY(ARRAY *p);
int main(void)
{ ARRAY my={NULL, 0, 0};

if(resizeARRAY( &my, NROWS, NCOLUMNS))
{my.array1[255][255] = 'c';
printf("my.arra y1[255][555] = \'%c\'\n", my.array1[255][255]);
}

freeARRAY(&my);
return 0;
}
int resizeARRAY(ARR AY* p, size_t nrows, size_t ncolumns)
{ size_t i;
unsigned char **temp;

if( (temp=realloc( p->array1, nrows * sizeof(*temp) )) == NULL )
R 0;
p->array1=temp;
for( i=0; i<nrows; i++ )
{p->array1[i]=malloc( ncolumns * sizeof( *(p->array1[i]) ) );
if(p->array1[i] == NULL)
{F( --i; i!=0; --i)
free( p->array1[i] );
free( p->array1[0] );
free( p->array1 );
R 0;
}
}
p->nrows = nrows ;
p->ncolumns = ncolumns;
return i; /* Ritorna il numero di righe allocate; */
}
void freeARRAY(ARRAY * p)
{ size_t i;

for(i=0; i < p->nrows; i++)
free( p->array1[i] );
free( p->array1 );
p->array1 = 0;
p->ncolumns = 0;
p->nrows = 0;
}
void freeARRAY1(ARRA Y* p)
{ size_t i;

for(i=0; i < p->nrows; i++)
free( p->array1[i] );
free( p->array1 );
free(p);
}

Nov 13 '05 #7
gi******@giusep pe.wwwew (Giuseppe) wrote (07 Jul 2003) in
news:3f******** ******@news.tin .it / comp.lang.c:
[...]
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for


He's back. And as stupid as ever.


--
Martin Ambuhl
Returning soon to the
Fourth Largest City in America
Nov 13 '05 #8
On Mon, 07 Jul 2003 16:17:23 GMT, in comp.lang.c ,
gi******@giusep pe.wwwew (Giuseppe) wrote:
On Sun, 06 Jul 2003 14:26:30 GMT, Al Bowers <xa*@abowers.co mbase.com>
wrote:
M-One wrote:
> Question 6.16 discuss this topic.
> http://www.eskimo.com/~scs/C-faq/q6.16.html
[...]
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for


Why do you persist in this obfuscatory stupidity? Do you think it
makes you look clever? Do you think its useful for others? Top Tip: it
makes you look a prat and everyone is ignoring you.
typedef struct ARRAY{
unsigned char **array1;
size_t nrows;
size_t ncolumns;
}ARRAY;


By common convention in C, uppercase is reserved for macros,
Microsoft's gratuitous ignoring of that convention notwithstanding .
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.c om/ms3/bchambless0/welcome_to_clc. html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #9
In article <3f************ **@news.tin.it> , gi******@giusep pe.wwwew
says...
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for

#define NROWS 256
#define NCOLUMNS 256
typedef struct ARRAY{
unsigned char **array1;
size_t nrows;
size_t ncolumns;
}ARRAY;

Okay, that's one time too many, I've given up. I don't normally
ever do this, but ...

*plonk*

--
Randy Howard
remove the obvious bits from my address to reply.
Nov 13 '05 #10

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

Similar topics

1
2568
by: ckroom | last post by:
Hi, I have a vector of chars: "FFFFFF" Each 2 chars from the vector in hex represents a decimal number, how can I convert the vector to 3 decimal values (char *)"FF"->(int)256. I have no idea. Thanks! -- ckroom http://nazaries.net/~ckroom
2
5059
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout What does it mean?
0
7700
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...
0
7924
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. ...
0
8125
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7974
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...
0
6284
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2114
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
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.