Exercise : i dont get it what it want me to do ...

boschow's Avatar, Join Date: Feb 2007
Go4Expert Member
Hi all,
i am trying to do a exercise, but i don't quite understand what exactly i need to do . . . the exercise states:

Define a pointer to a type double and reserve 1000 places. Then use this pointer as a table with 20 rows and 50 columns. Write a function, in which you will insert the beginning of the block and both indexes, the function will return the pointer on wanted place (double *place(double *, int, int).

thanks and best regards,
Alazer's Avatar, Join Date: Oct 2007
Newbie Member
in my opinion, this exercise's purpose is to let you maintain the memory like an array.
for example, the question askes you to malloc a new memory and treat it as an arry.

double* pdb = malloc(1000* sizeof(double));
then treat this memory, by the parameters with the function
double* place(double* ,int posRow, int posColumn), you can directly use the memory just like array!

I don't know wherther i misunderstand your meaning...............
boschow's Avatar, Join Date: Feb 2007
Go4Expert Member
I didnt do it like you said, but like this:

double *table_point(double *begin, int column, int row)
       int ret_row=0;
       int ret_col=0, temp_col;
       ret_row = (column + *begin)/column;
       ret_col = column * ret_row - *begin;
       ret_col = column - ret_col;
       return &(begin[ret_row][ret_col]);
The math is right and gives me the exact column and row, but the problem is that i dont know how to return a variable that has 2D array (see the code), if someone knows how to do this can please tell me...

Best regards,
DaWei's Avatar, Join Date: Dec 2006
Team Leader
See Alazar's post, the malloc statement.