I'm having some problems iterating through a bidimensional array,as I cn't print all the elements on a matrix form.Here's my code:
Code:
#include <stdio.h>
#include <string.h>
#define L1 3
#define C1 2
#define L2 4
#define C2 3
void escreve1(int mat[][C1],int lin, int col);
void escreve2(int mat[][C2],int lin, int col);
void main()
{
int mat1[L1][C1]={{1,2},{3,4},{5,6}};
int mat2[L2][C2]={{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
printf("\nMatriz mat1:\n");
escreve1(mat1, L1, C1);
printf("\nMatriz mat2:\n");
escreve2(mat2, L2, C2);
}
void escreve1(int mat[][C1] , int lin, int col)
{
int *z;
for(z=mat[0];z<mat[0]+col*lin;z++)
{
printf("%d\t",*z );
if(z==mat[0]+(col-1))
printf("\n");
}
}
void escreve2(int mat[][C2] , int lin, int col)
{
int *z;
for(z=mat[0];z<mat[0]+col*lin;z++)
{
printf("%d\t",*z );
if(z==mat[0]+(col-1))
printf("\n");
}
I want the output to be something like this:
Code:
Matriz mat1:
1 2
3 4
5 6
Matriz mat2:
1 2 3
4 5 6
7 8 9
10 11 12
Any help is very appreciated!
PS:The output I'm getting is:
Code:
Matriz mat1:
1 2
3 4 5 6
Matriz mat2:
1 2 3
4 5 6 7 8 9 10 11 12