Connecting Tech Pros Worldwide Forums | Help | Site Map

Help is need immidiately

vinod.bhavnani@gmail.com
Guest
 
Posts: n/a
#1: May 30 '06
Hello all,

I need desperate help

Here is the problem:

My problem today is with multidimensional arrays.

Lets say i have an array A[31][130][256][256] this is a 4 dimensional
static array.

How will i declare this same array with same dimensions dynamically and
also after dynamic declaration i want to be able to access contents of
array with indiceslike i should be able to access an elemt after after
dynamic declarartion as
A[23][34][56][78].Is this possible

Please help

Now pls remember that memory space for the array is not a concern and i
cant change this data structure

Thanks


Robert Gamble
Guest
 
Posts: n/a
#2: May 30 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com wrote:[color=blue]
> Hello all,
>
> I need desperate help
>
> Here is the problem:
>
> My problem today is with multidimensional arrays.
>
> Lets say i have an array A[31][130][256][256] this is a 4 dimensional
> static array.
>
> How will i declare this same array with same dimensions dynamically and
> also after dynamic declaration i want to be able to access contents of
> array with indiceslike i should be able to access an elemt after after
> dynamic declarartion as
> A[23][34][56][78].Is this possible
>
> Please help
>
> Now pls remember that memory space for the array is not a concern and i
> cant change this data structure[/color]

This is an FAQ question. The FAQ can be found at <http://c-faq.com/>,
your question is 6.16. If after reading the answer and trying to
implement the solution to fit your needs you have a specific question,
come back with what you have so far and a clear description of where
your problem lies.

Robert Gamble

Walter Roberson
Guest
 
Posts: n/a
#3: May 30 '06

re: Help is need immidiately


In article <1149003350.481589.262100@g10g2000cwb.googlegroups .com>,
<vinod.bhavnani@gmail.com> wrote:
[color=blue]
>I need desperate help[/color]
[color=blue]
>Now pls remember that memory space for the array is not a concern and i
>cant change this data structure[/color]

We generally find that people when people don't leave homework
to the last minute, that they don't need desperate immediate help.

[color=blue]
>Here is the problem:[/color]
[color=blue]
>My problem today is with multidimensional arrays.[/color]
[color=blue]
>Lets say i have an array A[31][130][256][256] this is a 4 dimensional
>static array.[/color]
[color=blue]
>How will i declare this same array with same dimensions dynamically[/color]

If it is the 'same array' then it would have the same properties
of being static and with those exact fixed dimensions. It would be
a contradiction in the question to ask to allocate a static array
dynamically, or to allocate an array with exact fixed dimensions
with variable dimensions.
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
vinod.bhavnani@gmail.com
Guest
 
Posts: n/a
#4: May 30 '06

re: Help is need immidiately


Hi,

After reading the stuff i still have no idea as to how u would proceed
with a 4 dimensional array.I would really appreiciate it if someone who
actually knows how to assign a dynamic 4-D array in C could please help
me out.

Thanks

vinod.bhavnani@gmail.com
Guest
 
Posts: n/a
#5: May 30 '06

re: Help is need immidiately


Hey,

Okay i havent written that correctly.There arent 2 arrays.I just want
to declare a dynamic array A[31][130][256][256] and access it with
indices like i would a static array.

Thanks

Eric Sosman
Guest
 
Posts: n/a
#6: May 30 '06

re: Help is need immidiately




vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:[color=blue]
> Hey,
>
> Okay i havent written that correctly.There arent 2 arrays.I just want
> to declare a dynamic array A[31][130][256][256] and access it with
> indices like i would a static array.[/color]

SomeType (*A)[31][130][256][256];
A = malloc(sizeof *A);
if (A == NULL)
abort();
A[1][2][3][4] = 42;

--
Eric.Sosman@sun.com

Default User
Guest
 
Posts: n/a
#7: May 30 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com wrote:
[color=blue]
> Hi,
>
> After reading the stuff i still have no idea as to how u would proceed
> with a 4 dimensional array.I would really appreiciate it if someone
> who actually knows how to assign a dynamic 4-D array in C could
> please help me out.[/color]

Please review the .sig information at the end of this message.

What about the FAQ answer confuses you? You haven't explained why you
are having problems. What have you tried? Have you created a 2-D
dynamic array?

What do you want a dynamic array? Normally that is for when you don't
know the size of the dimensions. This problem smells like homework. You
haven't presented the overall problem, just "how do I do a dynamic 4-D
array." You haven't said WHY you want such a beast, nor have you said
what you mean by such an array.



Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Barry Schwarz
Guest
 
Posts: n/a
#8: May 31 '06

re: Help is need immidiately


On Tue, 30 May 2006 12:50:17 -0400, Eric Sosman <Eric.Sosman@sun.com>
wrote:
[color=blue]
>
>
>vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:[color=green]
>> Hey,
>>
>> Okay i havent written that correctly.There arent 2 arrays.I just want
>> to declare a dynamic array A[31][130][256][256] and access it with
>> indices like i would a static array.[/color]
>
> SomeType (*A)[31][130][256][256];
> A = malloc(sizeof *A);
> if (A == NULL)
> abort();
> A[1][2][3][4] = 42;[/color]

I'm sure you really meant
(*A)[1][2][3][4] = 42;


Remove del for email
vinod.bhavnani@gmail.com
Guest
 
Posts: n/a
#9: May 31 '06

re: Help is need immidiately


this is all good but guys i need to access the arrays like
a static array and not with pointer referencing
like i need to access A with A[][][][].Please is there someone who can
suggest a technique.there have been many qs asked as to why i need the
array ,what about the memory,FAQs i need to read.I thought i can get
some real help here.Is there no one who can actually solve the
problem.Why is there a need to give an alternate solution.I dont
require alternates.This is the problem plain and simple i have a to
declare a 4 dimensional dynamic array and need to then aces it like a
static array with normal array indices like a[][][][] and not
*A(i*j*k).I know the compiler treats it the same .But i need the access
to it through A[][][][].Please anyone.I would really appreciate a
solution then some condesecnding remarks or an alterante solution.

Thanks,
Barry Schwarz wrote:[color=blue]
> On Tue, 30 May 2006 12:50:17 -0400, Eric Sosman <Eric.Sosman@sun.com>
> wrote:
>[color=green]
> >
> >
> >vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:[color=darkred]
> >> Hey,
> >>
> >> Okay i havent written that correctly.There arent 2 arrays.I just want
> >> to declare a dynamic array A[31][130][256][256] and access it with
> >> indices like i would a static array.[/color]
> >
> > SomeType (*A)[31][130][256][256];
> > A = malloc(sizeof *A);
> > if (A == NULL)
> > abort();
> > A[1][2][3][4] = 42;[/color]
>
> I'm sure you really meant
> (*A)[1][2][3][4] = 42;
>
>
> Remove del for email[/color]

Eric Sosman
Guest
 
Posts: n/a
#10: May 31 '06

re: Help is need immidiately




Barry Schwarz wrote On 05/30/06 20:48,:[color=blue]
> On Tue, 30 May 2006 12:50:17 -0400, Eric Sosman <Eric.Sosman@sun.com>
> wrote:
>
>[color=green]
>>
>>vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:
>>[color=darkred]
>>>Hey,
>>>
>>>Okay i havent written that correctly.There arent 2 arrays.I just want
>>>to declare a dynamic array A[31][130][256][256] and access it with
>>>indices like i would a static array.[/color]
>>
>> SomeType (*A)[31][130][256][256];
>> A = malloc(sizeof *A);
>> if (A == NULL)
>> abort();
>> A[1][2][3][4] = 42;[/color]
>
>
> I'm sure you really meant
> (*A)[1][2][3][4] = 42;[/color]

Good catch, but wrong diagnosis. What I *really*
meant was (ahem, ahem):

SomeType (*A)[130][256][256];
A = malloc(31 * sizeof *A);
if (A == NULL)
abort();
A[1][2[3][4] = 42;

(I guess you can tell who doesn't recall the last time
he used a 4D array ... Thanks for the eagle eye.)

--
Eric.Sosman@sun.com

Walter Roberson
Guest
 
Posts: n/a
#11: May 31 '06

re: Help is need immidiately


In article <1149098124.334737@news1nwk>,
Eric Sosman <Eric.Sosman@sun.com> wrote:
[color=blue]
> Good catch, but wrong diagnosis. What I *really*
>meant was (ahem, ahem):[/color]
[color=blue]
> SomeType (*A)[130][256][256];
> A = malloc(31 * sizeof *A);
> if (A == NULL)
> abort();
> A[1][2[3][4] = 42;[/color]

missing ] in line 42 ;-)

--
All is vanity. -- Ecclesiastes
Keith Thompson
Guest
 
Posts: n/a
#12: May 31 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com writes:[color=blue]
> this is all good but guys i need to access the arrays like
> a static array and not with pointer referencing
> like i need to access A with A[][][][].Please is there someone who can
> suggest a technique.there have been many qs asked as to why i need the
> array ,what about the memory,FAQs i need to read.I thought i can get
> some real help here.Is there no one who can actually solve the
> problem.Why is there a need to give an alternate solution.I dont
> require alternates.This is the problem plain and simple i have a to
> declare a 4 dimensional dynamic array and need to then aces it like a
> static array with normal array indices like a[][][][] and not
> *A(i*j*k).I know the compiler treats it the same .But i need the access
> to it through A[][][][].Please anyone.I would really appreciate a
> solution then some condesecnding remarks or an alterante solution.[/color]

Don't top-post. Read <http://www.caliburn.nl/topposting.html>.

What are you really trying to accomplish? If this is a homework
assignment, we're not going to do it for you (unless you give us your
instructor's e-mail address so we can submit the solution directly).

There should be enough information in the FAQ for you to figure out
how to solve the problem. What exactly is giving you trouble?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
W Marsh
Guest
 
Posts: n/a
#13: May 31 '06

re: Help is need immidiately


On Wed, 31 May 2006 18:11:34 GMT, Keith Thompson <kst-u@mib.org>
wrote:
[color=blue]
>vinod.bhavnani@gmail.com writes:[color=green]
>> this is all good but guys i need to access the arrays like
>> a static array and not with pointer referencing
>> like i need to access A with A[][][][].Please is there someone who can
>> suggest a technique.there have been many qs asked as to why i need the
>> array ,what about the memory,FAQs i need to read.I thought i can get
>> some real help here.Is there no one who can actually solve the
>> problem.Why is there a need to give an alternate solution.I dont
>> require alternates.This is the problem plain and simple i have a to
>> declare a 4 dimensional dynamic array and need to then aces it like a
>> static array with normal array indices like a[][][][] and not
>> *A(i*j*k).I know the compiler treats it the same .But i need the access
>> to it through A[][][][].Please anyone.I would really appreciate a
>> solution then some condesecnding remarks or an alterante solution.[/color]
>
>Don't top-post. Read <http://www.caliburn.nl/topposting.html>.
>
>What are you really trying to accomplish? If this is a homework
>assignment, we're not going to do it for you (unless you give us your
>instructor's e-mail address so we can submit the solution directly).
>
>There should be enough information in the FAQ for you to figure out
>how to solve the problem. What exactly is giving you trouble?[/color]

He may have a purely academic interest in seeing how a C++ expert
might express this. I know I do - I don't know how this would be done
(chaining?), and I would quite like to see some approaches.
Richard Heathfield
Guest
 
Posts: n/a
#14: May 31 '06

re: Help is need immidiately


W Marsh said:
[color=blue]
> He may have a purely academic interest in seeing how a C++ expert
> might express this.[/color]

I presume you mean "C expert".
[color=blue]
> I know I do - I don't know how this would be done
> (chaining?), and I would quite like to see some approaches.[/color]

Well, the FAQ covers it, pretty much.

Look, let's say you want a 1-D array of T. How would you do it? Like this?

#include <stdlib.h>

#include "t.h"

T *create_T_array(size_t z)
{
T *new = malloc(z * sizeof *new);
if(new != NULL)
{
size_t i = 0;
T blank = {0};
for(i = 0; i < z; i++)
{
new[i] = blank;
}
}
return new;
}

void destroy_T_array(T **old)
{
if(old != NULL && *old != NULL)
{
free(*old);
*old = NULL;
}
}

So - how would you create an array of such arrays?

T **create_TT_array(size_t y, size_t z)
{
T **new = malloc(y * sizeof *new);
if(new != NULL)
{
size_t i = 0;
int ok = 1;
for(i = 0; ok && i < y; i++)
{
new[i] = create_T_array(z);
if(new[i] == NULL)
{
ok = 0;
while(i > 0)
{
--i;
destroy_T_array(new + i);
}
free(new);
new = NULL;
}
}
}

return new;
}

And so on and so forth. You build up from inside, creating the functions
that you will need in the "outer" layers. It's very simple.


--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Al Balmer
Guest
 
Posts: n/a
#15: May 31 '06

re: Help is need immidiately


On 31 May 2006 09:41:51 -0700, vinod.bhavnani@gmail.com wrote:
[color=blue]
>this is all good but guys i need to access the arrays like
>a static array and not with pointer referencing
>like i need to access A with A[][][][].Please is there someone who can
>suggest a technique.there have been many qs asked as to why i need the
>array ,what about the memory,FAQs i need to read.I thought i can get
>some real help here.Is there no one who can actually solve the
>problem.Why is there a need to give an alternate solution.I dont
>require alternates.This is the problem plain and simple i have a to
>declare a 4 dimensional dynamic array and need to then aces it like a
>static array with normal array indices like a[][][][] and not
>*A(i*j*k).I know the compiler treats it the same .But i need the access
>to it through A[][][][].Please anyone.I would really appreciate a
>solution then some condesecnding remarks or an alterante solution.[/color]

That's not what this group is for. We'll be glad to help, but not do
your work for you. The relationship between pointers and array indexes
is very basic in C, and you should consult your textbooks. Try writing
something to do the job. If you can't make it work, post your code
here and ask for help.

If you really need someone else to do it for you, try one of the
*.sources.wanted groups.

--
Al Balmer
Sun City, AZ
W Marsh
Guest
 
Posts: n/a
#16: May 31 '06

re: Help is need immidiately


On Wed, 31 May 2006 19:01:55 +0000, Richard Heathfield
<invalid@invalid.invalid> wrote:
[color=blue]
>W Marsh said:
>[color=green]
>> He may have a purely academic interest in seeing how a C++ expert
>> might express this.[/color]
>
>I presume you mean "C expert".[/color]

Haha! I thought I was reading comp.lang.c++.

I'm just going to leave now.
Eric Sosman
Guest
 
Posts: n/a
#17: Jun 1 '06

re: Help is need immidiately


Walter Roberson wrote:[color=blue]
> In article <1149098124.334737@news1nwk>,
> Eric Sosman <Eric.Sosman@sun.com> wrote:
>
>[color=green]
>> Good catch, but wrong diagnosis. What I *really*
>>meant was (ahem, ahem):[/color]
>
>[color=green]
>> SomeType (*A)[130][256][256];
>> A = malloc(31 * sizeof *A);
>> if (A == NULL)
>> abort();
>> A[1][2[3][4] = 42;[/color]
>
>
> missing ] in line 42 ;-)[/color]

<Sigh.> Some days, it just doesn't pay to get out of bed.

--
Eric Sosman
esosman@acm-dot-org.invalid
santosh
Guest
 
Posts: n/a
#18: Jun 1 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com wrote:[color=blue]
> Barry Schwarz wrote:[color=green]
> > On Tue, 30 May 2006 12:50:17 -0400, Eric Sosman <Eric.Sosman@sun.com>
> > wrote:[color=darkred]
> > >vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:
> > >>
> > >> Okay i havent written that correctly.There arent 2 arrays.I just want
> > >> to declare a dynamic array A[31][130][256][256] and access it with
> > >> indices like i would a static array.
> > >
> > > SomeType (*A)[31][130][256][256];
> > > A = malloc(sizeof *A);
> > > if (A == NULL)
> > > abort();
> > > A[1][2][3][4] = 42;[/color]
> >
> > I'm sure you really meant
> > (*A)[1][2][3][4] = 42;
> >[/color]
> this is all good but guys i need to access the arrays like
> a static array and not with pointer referencing
> like i need to access A with A[][][][].Please is there someone who can
> suggest a technique.there have been many qs asked as to why i need the
> array ,what about the memory,FAQs i need to read.I thought i can get
> some real help here.Is there no one who can actually solve the
> problem.Why is there a need to give an alternate solution.I dont
> require alternates.This is the problem plain and simple i have a to
> declare a 4 dimensional dynamic array and need to then aces it like a
> static array with normal array indices like a[][][][] and not
> *A(i*j*k).I know the compiler treats it the same .But i need the access
> to it through A[][][][].Please anyone.I would really appreciate a
> solution then some condesecnding remarks or an alterante solution.[/color]

Please don't top-post.

Now, if I understand you right, you want to allocate a block of dynamic
memory such that you can use subscripts similar to four-dimensional
arrays to access the elements of the block... ?

The following code is one way I thought of. It's very inefficient and
importantly doesn't free() the allocated memory before program exit.
However it shows how you can use pointers to allocate a block of
dynamic memory and access it's elements *as if* it were a
four-dimensional static array.

Generally a N dimensional array of pointers of type T can provide
access to a N+1 dimensional array of objects of type *T. So, to access
a block of dynamic memory as a four-dimensional array, we must allocate
a three-dimensional array of pointers of the appropriate type. This
three-dimensional array of pointers can be accessed by a
two-dimensional array of pointers-to-pointers. This can in turn be
accessed by a one-dimensional array of
pointers-to-pointers-to-pointers. This is pointed to by a single
pointer-to-a-pointer-to-a-pointer-to-a-pointer.

/* Dynamically allocating a four dimensional array and using it */
#include <stdio.h>
#include <stdlib.h>

#define ARR_SIZ 10

int main(void) {
char ****array = NULL;
int cnt, cnt1, cnt2, cnt3;

if((array = malloc(ARR_SIZ * sizeof *array)) == NULL)
return EXIT_FAILURE;
for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
if((array[cnt] = malloc(ARR_SIZ * sizeof **array)) == NULL)
return EXIT_FAILURE;
}
for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
if((array[cnt][cnt1] =
malloc(ARR_SIZ * sizeof ***array)) == NULL)
return EXIT_FAILURE;
}
}
for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
if((array[cnt][cnt1][cnt2] =
malloc(ARR_SIZ * sizeof ****array)) ==
NULL)
return EXIT_FAILURE;
}
}
}

puts("Storing values in the array...");
for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
for(cnt3 = 0; cnt3 < ARR_SIZ; ++cnt3)
array[cnt][cnt1][cnt2][cnt3] = cnt3;
}
}
}

puts("Printing out the array...");
for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
for(cnt3 = 0; cnt3 < ARR_SIZ; ++cnt3) {
printf("array[%d][%d][%d][%d] = %d\n",
cnt, cnt1, cnt2, cnt3,
array[cnt][cnt1][cnt2][cnt3]);
}
}
}
}

exit(0);
}

vinod.bhavnani@gmail.com
Guest
 
Posts: n/a
#19: Jun 1 '06

re: Help is need immidiately


Hey,

Thank you santosh.Its been a pleasure.Someone finally who actually
knows how to solve the problem.Brilliant mate.No condescending
remarks..no pretences of actually "knowing" how to do it.No alternate
solution.Just plain and simple code.

Thanks

santosh wrote:[color=blue]
> vinod.bhavnani@gmail.com wrote:[color=green]
> > Barry Schwarz wrote:[color=darkred]
> > > On Tue, 30 May 2006 12:50:17 -0400, Eric Sosman <Eric.Sosman@sun.com>
> > > wrote:
> > > >vinod.bhavnani@gmail.com wrote On 05/30/06 12:46,:
> > > >>
> > > >> Okay i havent written that correctly.There arent 2 arrays.I just want
> > > >> to declare a dynamic array A[31][130][256][256] and access it with
> > > >> indices like i would a static array.
> > > >
> > > > SomeType (*A)[31][130][256][256];
> > > > A = malloc(sizeof *A);
> > > > if (A == NULL)
> > > > abort();
> > > > A[1][2][3][4] = 42;
> > >
> > > I'm sure you really meant
> > > (*A)[1][2][3][4] = 42;
> > >[/color]
> > this is all good but guys i need to access the arrays like
> > a static array and not with pointer referencing
> > like i need to access A with A[][][][].Please is there someone who can
> > suggest a technique.there have been many qs asked as to why i need the
> > array ,what about the memory,FAQs i need to read.I thought i can get
> > some real help here.Is there no one who can actually solve the
> > problem.Why is there a need to give an alternate solution.I dont
> > require alternates.This is the problem plain and simple i have a to
> > declare a 4 dimensional dynamic array and need to then aces it like a
> > static array with normal array indices like a[][][][] and not
> > *A(i*j*k).I know the compiler treats it the same .But i need the access
> > to it through A[][][][].Please anyone.I would really appreciate a
> > solution then some condesecnding remarks or an alterante solution.[/color]
>
> Please don't top-post.
>
> Now, if I understand you right, you want to allocate a block of dynamic
> memory such that you can use subscripts similar to four-dimensional
> arrays to access the elements of the block... ?
>
> The following code is one way I thought of. It's very inefficient and
> importantly doesn't free() the allocated memory before program exit.
> However it shows how you can use pointers to allocate a block of
> dynamic memory and access it's elements *as if* it were a
> four-dimensional static array.
>
> Generally a N dimensional array of pointers of type T can provide
> access to a N+1 dimensional array of objects of type *T. So, to access
> a block of dynamic memory as a four-dimensional array, we must allocate
> a three-dimensional array of pointers of the appropriate type. This
> three-dimensional array of pointers can be accessed by a
> two-dimensional array of pointers-to-pointers. This can in turn be
> accessed by a one-dimensional array of
> pointers-to-pointers-to-pointers. This is pointed to by a single
> pointer-to-a-pointer-to-a-pointer-to-a-pointer.
>
> /* Dynamically allocating a four dimensional array and using it */
> #include <stdio.h>
> #include <stdlib.h>
>
> #define ARR_SIZ 10
>
> int main(void) {
> char ****array = NULL;
> int cnt, cnt1, cnt2, cnt3;
>
> if((array = malloc(ARR_SIZ * sizeof *array)) == NULL)
> return EXIT_FAILURE;
> for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
> if((array[cnt] = malloc(ARR_SIZ * sizeof **array)) == NULL)
> return EXIT_FAILURE;
> }
> for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
> for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
> if((array[cnt][cnt1] =
> malloc(ARR_SIZ * sizeof ***array)) == NULL)
> return EXIT_FAILURE;
> }
> }
> for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
> for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
> for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
> if((array[cnt][cnt1][cnt2] =
> malloc(ARR_SIZ * sizeof ****array)) ==
> NULL)
> return EXIT_FAILURE;
> }
> }
> }
>
> puts("Storing values in the array...");
> for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
> for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
> for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
> for(cnt3 = 0; cnt3 < ARR_SIZ; ++cnt3)
> array[cnt][cnt1][cnt2][cnt3] = cnt3;
> }
> }
> }
>
> puts("Printing out the array...");
> for(cnt = 0; cnt < ARR_SIZ; ++cnt) {
> for(cnt1 = 0; cnt1 < ARR_SIZ; ++cnt1) {
> for(cnt2 = 0; cnt2 < ARR_SIZ; ++cnt2) {
> for(cnt3 = 0; cnt3 < ARR_SIZ; ++cnt3) {
> printf("array[%d][%d][%d][%d] = %d\n",
> cnt, cnt1, cnt2, cnt3,
> array[cnt][cnt1][cnt2][cnt3]);
> }
> }
> }
> }
>
> exit(0);
> }[/color]

Keith Thompson
Guest
 
Posts: n/a
#20: Jun 1 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com writes:[color=blue]
> Thank you santosh.Its been a pleasure.Someone finally who actually
> knows how to solve the problem.Brilliant mate.No condescending
> remarks..no pretences of actually "knowing" how to do it.No alternate
> solution.Just plain and simple code.[/color]
[...]

Please stop top-posting. See <http://www.caliburn.nl/topposting.html>.

You got a lot of negative feedback on your original question. The
reason for this is that you stated a problem and demanded that we
write the code to solve it for you. We tried to point you to a
resource (the FAQ) that should have helped you solve the problem
yourself. You never explained just why you need to do this.

If this was homework, the point is for you to learn how to do it
yourself. If the rest of us are going to write all the code, why is
your participation necessary?

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Al Balmer
Guest
 
Posts: n/a
#21: Jun 1 '06

re: Help is need immidiately


On 1 Jun 2006 10:28:38 -0700, vinod.bhavnani@gmail.com wrote:
[color=blue]
>Thank you santosh.Its been a pleasure.Someone finally who actually
>knows how to solve the problem.Brilliant mate.No condescending
>remarks..no pretences of actually "knowing" how to do it.No alternate
>solution.Just plain and simple code.[/color]

I expect that everyone who replied knows how to do it. However, they
apparently failed in their goal of letting you learn how to do it. Too
bad - Santosh did you a disservice, but perhaps you can hire him the
next time you need a program written.

--
Al Balmer
Sun City, AZ
santosh
Guest
 
Posts: n/a
#22: Jun 1 '06

re: Help is need immidiately


Al Balmer wrote:[color=blue]
> On 1 Jun 2006 10:28:38 -0700, vinod.bhavnani@gmail.com wrote:
>[color=green]
> >Thank you santosh.Its been a pleasure.Someone finally who actually
> >knows how to solve the problem.Brilliant mate.No condescending
> >remarks..no pretences of actually "knowing" how to do it.No alternate
> >solution.Just plain and simple code.[/color]
>
> I expect that everyone who replied knows how to do it. However, they
> apparently failed in their goal of letting you learn how to do it. Too
> bad - Santosh did you a disservice,...[/color]

Eh, how do come to that conclusion? Whom did I do a "disservice"? The
OP? Well, if he's intelligent and serious about programming, he'll
study my code, (and other material), and figure it out himself. If he's
not and he uses my code, as such, for his project, then that's his
descision and problem. He'll come a cropper someday or the other.
Either way, I don't consider my post a "disservice". Depending on what
the OP does with it, he'll create his own advantage or "disservice" for
himself.

Following your line of thought, guns should be banned in the US
because, *some* angsty kid decides to test the trigger. Or all source
code should be removed from the internet, because people like the OP
may allegedly use it to further their mis-education. Further, pete will
be heartened to hear that you consider his contributions to the group a
"disservice".
[color=blue]
> but perhaps you can hire him the next time you need a program written.[/color]

No need to insult me just because the OP happened to criticise the
group.

santosh
Guest
 
Posts: n/a
#23: Jun 1 '06

re: Help is need immidiately


vinod.bhavnani@gmail.com wrote:[color=blue][color=green][color=darkred]
> >> vinod.bhavnani@gmail.com wrote:[/color][/color][/color]
.... snip ...[color=blue][color=green][color=darkred]
> > >> this is all good but guys i need to access the arrays like
> > >> a static array and not with pointer referencing[/color][/color][/color]
.... snip ...[color=blue][color=green]
> > santosh wrote:
> > Please don't top-post.
> >
> > Now, if I understand you right, you want to allocate a block of dynamic
> > memory such that you can use subscripts similar to four-dimensional
> > arrays to access the elements of the block... ?
> >
> > The following code is one way I thought of. It's very inefficient and
> > importantly doesn't free() the allocated memory before program exit.[/color][/color]
.... snip ...[color=blue]
>
> Hey,
>
> Thank you santosh.Its been a pleasure.Someone finally who actually
> knows how to solve the problem.Brilliant mate.No condescending
> remarks..no pretences of actually "knowing" how to do it.No alternate
> solution.Just plain and simple code.
>
> Thanks[/color]

No problem but generally the regulars of this group are *far* more well
versed in C than you or me. In my short time here, I've learned quite a
bit about writing good C code that would otherwise have been learnt
much slower, if my only sources had been books and tutorials.

As for your question, the FAQ entry, (reffered to you in the first
reply to your post), actually has enough pointers, (pardon the pun) to
enable you to figure it out yourself. I'll admit that multidimensional
arrays and pointers are not the easiest aspects of C, but generally
they can be tackled if you proceed systematically from the fundamental
concepts and syntax, trying out progressively more complex demos
yourself.

Al Balmer
Guest
 
Posts: n/a
#24: Jun 1 '06

re: Help is need immidiately


On 1 Jun 2006 12:28:26 -0700, "santosh" <santosh.k83@gmail.com> wrote:
[color=blue]
>Al Balmer wrote:[color=green]
>> On 1 Jun 2006 10:28:38 -0700, vinod.bhavnani@gmail.com wrote:
>>[color=darkred]
>> >Thank you santosh.Its been a pleasure.Someone finally who actually
>> >knows how to solve the problem.Brilliant mate.No condescending
>> >remarks..no pretences of actually "knowing" how to do it.No alternate
>> >solution.Just plain and simple code.[/color]
>>
>> I expect that everyone who replied knows how to do it. However, they
>> apparently failed in their goal of letting you learn how to do it. Too
>> bad - Santosh did you a disservice,...[/color]
>
>Eh, how do come to that conclusion? Whom did I do a "disservice"? The
>OP? Well, if he's intelligent and serious about programming, he'll
>study my code, (and other material), and figure it out himself.[/color]

No, he won't. (Witholding judgment on his intelligence and
seriousness.) Why should he, when he can get someone else to do it?
[color=blue]
> If he's
>not and he uses my code, as such, for his project, then that's his
>descision and problem. He'll come a cropper someday or the other.
>Either way, I don't consider my post a "disservice". Depending on what
>the OP does with it, he'll create his own advantage or "disservice" for
>himself.
>
>Following your line of thought, guns should be banned in the US
>because, *some* angsty kid decides to test the trigger.[/color]

Huh? Are you saying that kids should not be encouraged to learn how to
handle a gun, but should always depend on someone else to do it for
them? That's a different issue, and perhaps you think that's the case,
but that's not the practice here wrt learning C. We try to help people
learn, rather than doing their work for them. As I pointed out, if the
OP wants someone to do the work for him, there are other venues.
[color=blue]
> Or all source
>code should be removed from the internet, because people like the OP
>may allegedly use it to further their mis-education.[/color]

Huh? Again. I would encourage the OP to study and use other people's
sources. If he has difficulty understanding it, he can ask for help
here. But that has nothing to do with insisting that someone else do
his work and refusing even to try doing it himself.
[color=blue]
> Further, pete will
>be heartened to hear that you consider his contributions to the group a
>"disservice".
>[/color]
Huh? Once again. Who's Pete?
[color=blue][color=green]
>> but perhaps you can hire him the next time you need a program written.[/color]
>
>No need to insult me just because the OP happened to criticise the
>group.[/color]

Four for four. How on earth did you detect an insult in that? I
certainly wouldn't suggest it if I didn't think you were competent.

--
Al Balmer
Sun City, AZ
Closed Thread