Jan 29, 2012 at 9:27pm UTC
the values are stored wrong ... any comment??
void main()
{
int x,y;
cin>>x>>y;
int** s_Matrix;
s_Matrix = (int**) malloc(x*sizeof(int*));
for (int i = 0; i < x; i++)
s_Matrix[i] = (int*) malloc(y*sizeof(int));
//
for (int i = 0; i < x; i++)
{
for (int j = 0; j < y; j++)
{
if(i==j)
*s_Matrix[i,j]= 2;
else
*s_Matrix[i, j] = 1;
}
}
for (int i1 = 0; i1 < x; i1++)
{
for (int j1 = 0; j1 < y; j1++)
{
cout<<"s["<<i1<<","<<j1<<"]="<<*Seq_Matrix[i1, j1]<<"\t" ;
}
cout<<endl;
}
//////////////
}
thanks,
Jan 29, 2012 at 9:37pm UTC
void main()
This is incorrect. main() returns an int .
s_Matrix[i,j]
does not do what you think it does. Did you mean s_Matrix[i][j]
?
Whilst technically this is a C++ array, it is much more C than C++. Consider not using C style arrays and instead make use of the C++ alternatives.
Last edited on Jan 29, 2012 at 9:38pm UTC
Jan 29, 2012 at 9:49pm UTC
thanks Moschops .. it worked after modifying it to s_Matrix[i][j] and removing the *...
i admit i have problems with pointers :( and i have to work with C.