multidimensional arrays

S

Stefan Ram

Here is a programming exercise, I just made up after reading
the other thread named »multidimensional heap arrays«:

Write the following functions (using stdarg.h):

a = aalloc( n, ... )

Allocates an n dimensional int array with the n extensions
given after the first argument, for example, aalloc( 2, 3, 6 )
for a two-dimensional 3x6 array. The type of »a« might be
whatever you need, it does not have to be an array type of
the language C, but also might be a pointer to a struct or so.
It does only need to be accessible by the following other
operations:

int aget( a, ... )

Get the value at the position given by the arguments after
the first argument. (The behavior only needs to be defined
for the case that there are n such arguments, when »a« is
the result of a preceding call to aalloc( n, ... ).)

aset( a, i, ... )

Sets the value at the given position ... to i.

aprint( a, FILE * )

Serialize the array to the file.

aread( a, FILE * )

afree( a )

Release all the resources allocated in a preceding aalloc.
 

Ask a Question

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.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top