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