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

Discussion in 'C' started by boschow, Oct 22, 2007.

1. ### boschowNew Member

Joined:
Feb 22, 2007
Messages:
32
0
Trophy Points:
0
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.

2. ### AlazerNew Member

Joined:
Oct 23, 2007
Messages:
2
0
Trophy Points:
0
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...............

3. ### boschowNew Member

Joined:
Feb 22, 2007
Messages:
32
0
Trophy Points:
0
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.

Joined:
Dec 6, 2006
Messages:
835