linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pass 2 D array in C
@ 2004-10-14 11:26 Ankit Jain
  2004-10-14 13:08 ` Luciano Moreira - igLnx
  0 siblings, 1 reply; 3+ messages in thread
From: Ankit Jain @ 2004-10-14 11:26 UTC (permalink / raw)
  To: linux prg

its a simple question...

how to pass a 2 D array address in C

is there any way by **pointer?

thanks

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pass 2 D array in C
  2004-10-14 11:26 pass 2 D array in C Ankit Jain
@ 2004-10-14 13:08 ` Luciano Moreira - igLnx
  2004-10-14 13:13   ` Luciano Moreira - igLnx
  0 siblings, 1 reply; 3+ messages in thread
From: Luciano Moreira - igLnx @ 2004-10-14 13:08 UTC (permalink / raw)
  To: Ankit Jain; +Cc: linux prg

The following sample was coded now, without compiling, then It can have 
some mistakes for compiler.
But I think that it ll can be good for your analyse. Using this sample, 
you can allocate any kind of array, like as 3D, 4D, 5D, and so on.

Luciano
-----------------------------------------------------------------------------------------
main()
{
   int THE_LENGTH = 200; /* Numbers of itens of array */
   long **p2DArray;

   pp2DArray = new long[THE_LENGTH];
   /* for C-ANSI: pp2DArray = malloc(sizeof(long) * THE_LENGTH); */

   fill_array(pp2dArray, THE_LENGTH);
   dump_array(pp2dArray, THE_LENGTH);

   delete pp2DArray;
  /* forC-ANSI:  free(pp2DArray); */
}

fill_array(char *pp, int nLength)
{
   int ct;
   for ct(=0; ct<nLength; ct++) {
      ppArray[ct] = (long) rand();
   }
}


dump_array(char *pp, int nLength)
{
   int ct;
   for (ct=0; ct<nLength; ct++) {
      printf("Item %d: %ld\n", ct, ppArray[ct]);
   }
}
-----------------------------------------------------------------------------------------



Ankit Jain escreveu:

>its a simple question...
>
>how to pass a 2 D array address in C
>
>is there any way by **pointer?
>
>thanks
>
>ankit
>
>________________________________________________________________________
>Yahoo! Messenger - Communicate instantly..."Ping" 
>your friends today! Download Messenger Now 
>http://uk.messenger.yahoo.com/download/index.html
>-
>To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>  
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: pass 2 D array in C
  2004-10-14 13:08 ` Luciano Moreira - igLnx
@ 2004-10-14 13:13   ` Luciano Moreira - igLnx
  0 siblings, 0 replies; 3+ messages in thread
From: Luciano Moreira - igLnx @ 2004-10-14 13:13 UTC (permalink / raw)
  Cc: Ankit Jain, linux prg

Sorry, I found 2 big mistakes !!!
the functions parameters, should be:

fill_array(char **pp, int nLength)
dump_array(char **pp, int nLength)

instead of:
fill_array(char *pp, int nLength)
dump_array(char *pp, int nLength)



Luciano Moreira - igLnx escreveu:

> The following sample was coded now, without compiling, then It can 
> have some mistakes for compiler.
> But I think that it ll can be good for your analyse. Using this 
> sample, you can allocate any kind of array, like as 3D, 4D, 5D, and so 
> on.
>
> Luciano
> ----------------------------------------------------------------------------------------- 
>
> main()
> {
>   int THE_LENGTH = 200; /* Numbers of itens of array */
>   long **p2DArray;
>
>   pp2DArray = new long[THE_LENGTH];
>   /* for C-ANSI: pp2DArray = malloc(sizeof(long) * THE_LENGTH); */
>
>   fill_array(pp2dArray, THE_LENGTH);
>   dump_array(pp2dArray, THE_LENGTH);
>
>   delete pp2DArray;
>  /* forC-ANSI:  free(pp2DArray); */
> }
>
> fill_array(char *pp, int nLength)
> {
>   int ct;
>   for ct(=0; ct<nLength; ct++) {
>      ppArray[ct] = (long) rand();
>   }
> }
>
>
> dump_array(char *pp, int nLength)
> {
>   int ct;
>   for (ct=0; ct<nLength; ct++) {
>      printf("Item %d: %ld\n", ct, ppArray[ct]);
>   }
> }
> ----------------------------------------------------------------------------------------- 
>
>
>
>
> Ankit Jain escreveu:
>
>> its a simple question...
>>
>> how to pass a 2 D array address in C
>>
>> is there any way by **pointer?
>>
>> thanks
>>
>> ankit
>>
>> ________________________________________________________________________
>> Yahoo! Messenger - Communicate instantly..."Ping" your friends today! 
>> Download Messenger Now http://uk.messenger.yahoo.com/download/index.html
>> -
>> To unsubscribe from this list: send the line "unsubscribe 
>> linux-c-programming" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>>
>>  
>>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-14 13:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-14 11:26 pass 2 D array in C Ankit Jain
2004-10-14 13:08 ` Luciano Moreira - igLnx
2004-10-14 13:13   ` Luciano Moreira - igLnx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).