hello...
anyone knew how to declare and operate a big multidimensional array by using virtual array (macros ?) ... ?
hello...
anyone knew how to declare and operate a big multidimensional array by using virtual array (macros ?) ... ?
What's a "virtual array"? Do you mean a dynamicly allocated array? Or what? In either case, you'll always need to know the number of dimensions so you can dereference it correctly.
You can fake a multidimensional array by simply creating a single dimension array and applying the appropriate math to access the correct 'cell' in the arrray.
Vola!Code:char *array; int *dimensions, dim, count, size; dim = promptfordimensions( ); dimensions = malloc( dim * sizeof(int) ); for( count = 0; count < dim; count++ ) dimensions[count] = promptforsizeofdim( ); for( size = 1, count = 0; count < dim; count++ ) size *= dimensions[count]; array = malloc( size * sizeof( char ) );
Quzah.
Hope is the first step on the road to disappointment.
hello...
Virtual array I meant is array that use virtual memory.......
Where are codes of func. prototypes :
promptfordimensions( );
promptforsizeofdim( );
Thank ya....
A virtual Array is not really an array. It's a list. They are similar but operations on the two happen very differently.
an array is a static piece of contiguous memory that's allocated at program runtime. This is finite in size and cannot grow in size if needed.
You access "members" of an array using the [ i ] ( or sub i ) iterator. This is not so with "dynamic" memory allocation.
Sounds to me like you want an array of data that gets it's memory dynamically during the program execution. In C, we call this a linked list. For which you need to allocate memory on the fly and then manipulate some pointers to either insert or delete a piece of data.
Before I go on any further, have you covered linked lists in your coursework? I don't want to go into a bigger explaination unless I am on target here.
Mike
NEVER PET YOUR DOG WHILE IT'S ON FIRE!
Yeah. My code should give you what you need then. Sound like exactly what you need.Originally posted by andu
hello...
Virtual array I meant is array that use virtual memory.......
You mean to tell me you don't know how to prompt the user for a number? And you're trying to use virtual memory? Woah there. One step at a time. First leanr how to prompt the user for a number and store it, then you can tackle something bigger like virtual memory.Originally posted by andu
Where are codes of func. prototypes :
promptfordimensions( );
promptforsizeofdim( );
In other words: I figured any idiot should know how to prompt for a number, so there is no point in me writing that for you.
Quzah.
Hope is the first step on the road to disappointment.