Re: [Dev-C++] How i convert a char matrix to int matrix ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ferdinando F. <s2...@st...> - 2003-12-17 18:18:29
|
On Wed, 17 Dec 2003 hu...@cl... wrote:
> Hei all,
> i have this matrix :
>
> char matrix[5][5] =
> {{'0','0','0','0','0'},
> {'0','0','0','0','0'},
> {'0','0','0','0','0'},
> {'0','0','0','0','0'},
> {'0','0','0','0','0'}
> };
>
> and i have this function :
>
> void show_matrix(int m[5][5))
The only way to do it, if you can't modify one of the objects, is to
allocate a matrix of this kind:
int matrix_int[5][5] = {
{matrix[0][0], matrix[0][1], // ... and so on
but you have to create a new object, it is possible only if you know that
your matrix is small (5x5 makes cheap the job, for a 100x100 I'd think a
better solution). Obviously you can allocate an empty object and then
populate it with a for, treating the char matrix as a vector; if you
accept this solution, I suggest you create a proxy function (for instance
void show_char_matrix (...)) which allocate the matrix_int object and then
call show_matrix.
Hope I helped
Ferdinando
|