#include <iostream>
usingnamespace std;
int main(){
int a, b,i,j;
a=b=0;
int **m;
cout<<"Ingrese la cantidad de Filas seguido de la cantidad de columnas de la Matriz"<<endl;
cin>>a>>b;
m = newint *[a]; // array de A punteros a int
for(int i=0;i<a+1;i++)m[i]= newint[b]; // m es un array de [a]*[b]
cout<<"Ingrese la matriz por filas"<<endl;
for(i=0;i<a;i++){
for(j=0;j<b;j++)
cin>>m[i][j];
}
for(i=0;i<b;i++){
for(j=0;j<a;j++)
cout<<m[i][j];
cout<<endl;
}
delete[] m;
system("pause");
return 0;
}
which work correctly but... when i want that a funtion show the matriz i can't make the correct use of the pointers...
/*10.3 The prototype of a function is: void escribe_mat (int* t, int nf, int nc). The function has as intention show for screen the counterfoil for columns. The first argument corresponds(fits) with an entire counterfoil, the second one and the third one is the number of rows and columns of the counterfoil. Write the implementation applying the arithmetic of punteros.*/
#include <iostream>
usingnamespace std;
void escribemat(int* t,int nf,int nc);
int main(){
int a, b,i,j;
a=b=0;
int **m;
cout<<"Ingrese la cantidad de Filas seguido de la cantidad de columnas de la Matriz"<<endl;
cin>>a>>b;
m = newint *[a]; // array de A punteros a int
for(int i=0;i<a+1;i++)m[i]= newint[b]; // m es un array de [a]*[b]
cout<<"Ingrese la matriz por filas"<<endl;
for(i=0;i<a;i++){
for(j=0;j<b;j++)
cin>>m[i][j];
}
/*for(i=0;i<b;i++){
for(j=0;j<a;j++)
cout<<m[i][j];
cout<<endl;
}*/
escribemat(&m,a,b);
delete[] m;
system("pause");
return 0;
}
void escribemat(int* t,int nf,int nc){
int i,j;
for(i=0;i<nc;i++){
for(j=0;j<nf;j++)
cout<<* t[i][j];
cout<<endl;
}
}
And this appear in the part of errors:
1)Cannot convert 'int***' to 'int*' for argument '1' to 'void escribemat(int*,int,int)---- Line 34
2)Invalid types 'int[int]' for array subscript --- Line 46
I didn't look at the code in detail, but:
1) Your function is declared as only taking an int*, yet you pass it a int*** and seem to treat it as such. Try changing the first parameter (t) to be int***
2) This comes from the same problem as 1. The compiler thinks you have a int*, so you can't treat it like an int***