c++ problems with array+function+pointers

Hi! well here is the problem i have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace 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 = new int *[a]; // array de A punteros a int
	for(int i=0;i<a+1;i++)m[i]= new int[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.*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace 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 = new int *[a]; // array de A punteros a int
	for(int i=0;i<a+1;i++)m[i]= new int[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
Last edited on
Code tags please.

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***
thanks yes that was the problem je
Topic archived. No new replies allowed.