[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] tilgaa 2-dim array



----- Original Message ----- 
From: <sslug@sslug>
> Hej c-liste,
> hvordan erklærer jeg et 2-dim-array uden fast længde og sender det med et
> funktionskald, og tilgår det?

Hvis det var mig ville jeg gøre sådan:

int** makeIntMatrix(int width, int height)
{
 int i, j;
 int* data;
 int** index;
 
 data = (int*)malloc(width*height*sizeof(int));
 index = (int**)malloc(height*sizeof(int*));
 
 for(i=0, j=0; i<height*width; i+=width)
  index[j++] = data+i;
 return index;
}

void print_matrix(int **matrix, int w, int h)
{
 int i, j;

 for(i=0; i<h; i++)
  for(j=0; j<w; j++)
   printf("%i", matrix[i][j]);
}

void main()
{
 int **matrix;
 matrix = makeIntMatrix(10, 20);
 print_matrix(matrix, 10, 20);
}

MVH
/Kasper

- - - - - -
Get PGP key from www.keyserver.net - Key ID: 0xDE21F438
Name = Kasper Bonne
Fingerprint = B583 0E69 166A 15EF B6F8 B248 7558 DB7C DE21 F438 
- - - - - -


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *