M
M-One
See subject: how do I calloc (and free the memory, if that's not
free(my_bytes) this?
TIA!
free(my_bytes) this?
TIA!
M-One said:See subject: how do I calloc (and free the memory, if that's not
free(my_bytes) this?
TIA!
M-One said: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>
#define P printf
#define R return
#define F for
[...]
#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for
typedef struct ARRAY{
unsigned char **array1;
size_t nrows;
size_t ncolumns;
}ARRAY;
[email protected] said:#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;
Giuseppe said:[...]M-One said:Question 6.16 discuss this topic.
http://www.eskimo.com/~scs/C-faq/q6.16.html
#define R return
return 0;
int resizeARRAY(ARRAY** p, size_t nrows, size_t ncolumns)
{ size_t i, j=0;
unsigned char **temp;
if(*p==0) {if( (*p=malloc(sizeof(**p)))==0 )
R 0;
j=1;
}
if( (temp=realloc( (*p)->a, nrows * sizeof(*temp) )) == NULL )
{if(j) free( *p );
*p=0;
R 0;
}
(*p)->a=temp;
for( i=0; i<nrows; i++ )
{(*p)->a=malloc( ncolumns * sizeof( *((*p)->a) ) );
if((*p)->a == NULL)
{if(i)
F( --i; i!=0; --i)
free( (*p)->a );
free( (*p)->a[0] );
free( (*p)->a );
if(j) {free( *p ); *p=0; }
R 0;
}
}
(*p)->nrows = nrows ;
(*p)->nco = ncolumns;
return i; /* Ritorna il numero di colonne allocate; */
}
Giuseppe said:#include <stdio.h>
#include <stdlib.h>
Giuseppe said:#include <stdio.h>
#include <stdlib.h>
#define P printf
#define R return
#define F for
Ho fatto una compilazione con gcc e in questa linea risulta un#include <stdio.h>
qui c'è un ; di troppo#include <stdlib.h>
#define P printf
#define R return
#define F for
#define NROWS 256
#define NCOLUMNS 256
typedef struct ARRAY{
unsigned char** a;
size_t nrows;
size_t nco;
}ARRAY;
int creaARRAY(ARRAY** p, size_t nrows, size_t ncolumns);
int rszARRAY (ARRAY** p, size_t nrows, size_t ncolumns);
void freeARRAY (ARRAY* p);
void freeARRAY_d(ARRAY* p);
ARRAY* somma (ARRAY* r, ARRAY* a, ARRAY* b);
void stampa (ARRAY* a);
int main(void)
{
ARRAY my={NULL, 0, 0}, *r=0, *a=0, *b=0, *mmy=&my;
if(creaARRAY(&mmy, NROWS, NCOLUMNS))
{my.a[255][255] = 'c';
printf("my.array1[255][255] = \'%c\'\n", my.a[255][255]);
}
if(rszARRAY(&mmy, NROWS+100, NCOLUMNS+100))
{my.a[255+100][255+100] = 'c';
printf("my.array1[255+100][255+100] = \'%c\'\n",
my.a[255+100][255+100]);
}
freeARRAY(&my);
if(creaARRAY(&r, 3, 3) * creaARRAY(&a, 3, 3)*
creaARRAY(&b, 3, 3)!= 0 )
{
a->a[0][0]= 9; a->a[0][1]=15; a->a[0][2]=20;
a->a[1][0]=10; a->a[1][1]=14; a->a[1][2]=20;
a->a[2][0]=10; a->a[2][1]=15; a->a[2][2]=19;
b->a[0][0]=1 ; b->a[0][1]=1 ; b->a[0][2]=2 ;
b->a[1][0]=1 ; b->a[1][1]=1 ; b->a[1][2]=2 ;
b->a[2][0]=1 ; b->a[2][1]=1 ; b->a[2][2]=2 ;
if(somma(r, a, b));
{stampa(a);P("+\n"); stampa(b);P("==\n"); stampa(r);}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.