[algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
Is there any way to dynamically allocate a 2-D array using *using single call to malloc* in C ? -- regards Apoorve Mohan -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algogeeks@googlegroups.com. To

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread hary rathor
#includestdlib.h int main () { int *mat; int i,j; int ROW=4; int COL=3; int k=0; mat=(int *)malloc(ROW*COL*sizeof(int)); for(i=0;iROW;i++) for(j=0;jCOL;j++) mat[i*COL+j]=++k; for(i=0;iROW;i++) for(j=0;jCOL;j++) printf(%d,,mat[i*COL+j]); return 0;

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
though thankx :) On Thu, Jun 30, 2011 at 12:44 AM, Apoorve Mohan apoorvemo...@gmail.comwrote: @above: man i need a 2d array not a 1d array... On Thu, Jun 30, 2011 at 12:38 AM, hary rathor harry.rat...@gmail.comwrote: #includestdlib.h int main () { int *mat; int i,j; int

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Piyush Sinha
int **p; p = (int **)malloc(sizeof(int *)*row); for(i = 0;irow;i++) p[i] = (int *)malloc(sizeof(int)*column); On 6/30/11, Apoorve Mohan apoorvemo...@gmail.com wrote: though thankx :) On Thu, Jun 30, 2011 at 12:44 AM, Apoorve Mohan apoorvemo...@gmail.comwrote: @above: man i need a 2d

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Apoorve Mohan
@piyush: only one call to malloc...ur sol has 2 On Thu, Jun 30, 2011 at 12:58 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: int **p; p = (int **)malloc(sizeof(int *)*row); for(i = 0;irow;i++) p[i] = (int *)malloc(sizeof(int)*column); On 6/30/11, Apoorve Mohan apoorvemo...@gmail.com

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread Piyush Sinha
ohh sorrymy bad...i didnt read the whole question..i just read the subject...:P i think its not possible if u want other than hary's solution... On 6/30/11, Apoorve Mohan apoorvemo...@gmail.com wrote: @piyush: only one call to malloc...ur sol has 2 On Thu, Jun 30, 2011 at 12:58 AM, Piyush

Re: [algogeeks] 2 D array(dynamic allocation)

2011-06-29 Thread rizwan hudda
I have solved this using one malloc find the code in http://ideone.com/BV9Kj On Thu, Jun 30, 2011 at 1:20 AM, Piyush Sinha ecstasy.piy...@gmail.com wrote: ohh sorrymy bad...i didnt read the whole question..i just read the subject...:P i think its not possible if u want other than hary's