Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Exercise : i dont get it what it want me to do ... (http://www.go4expert.com/forums/exercise-i-dont-t6973/)

boschow 23Oct2007 02:21

Exercise : i dont get it what it want me to do ...
 
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,
BoSCHoW.

Alazer 23Oct2007 07:54

Re: Exercise : i dont get it what it want me to do ...
 
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 23Oct2007 23:53

Re: Exercise : i dont get it what it want me to do ...
 
I didnt do it like you said, but like this:

Code:

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,
BoSCHoW.

DaWei 24Oct2007 01:17

Re: Exercise : i dont get it what it want me to do ...
 
See Alazar's post, the malloc statement.


All times are GMT +5.5. The time now is 21:34.