Hi,
Apparently I write a little code which use "new" inside of my function, but it appear that it do not work well.
and it return "Segmentation fault"
I guess "new" do not work properly.
Does anyone have any ideas ?
Thanks in advance.
Apparently I write a little code which use "new" inside of my function, but it appear that it do not work well.
Code:
#include "iostream"
#include "cstdlib"
#include "iomanip"
using namespace std;
void inputMatrix(double **M,int& line,int& col){
cout << "Input number of lines and columns : ";
cin>>line>>col;
M=new double*[line];
for (int i=0; i<line; i++) {
M[i]=new double[col];
}
cout << "Input your matrix :"<<endl;
for (int i=0; i<line; i++)
for (int j=0; j<col; j++) cin>>M[i][j];
}
void killMatrix(double **M,int line,int col){
cout<<"DD";
for (int i=0; i<line; i++) delete[] M[i];
delete[] M;
}
int main(){
int line1,col1,line2,col2;
double **M1,**M2,**result;
inputMatrix(M1,line1,col1);
cout<<line1<<" "<<col1<<endl;
cout<<M1[0][1]<<endl;
// inputMatrix(M2,line2,col2);
// cout<<line2<<" "<<col2<<endl;
// result=add2Matrix(M1,M2,line1,col1,line2,col2);
// outputMatrix(result,line1,col1);
killMatrix(M1,line1,col1);
// killMatrix(M2,line2,col2);
// killMatrix(result,line1,col1);
return 0;
}
and it return "Segmentation fault"
I guess "new" do not work properly.
Does anyone have any ideas ?
Thanks in advance.