Advertisement

Things aint workin out.

Started by May 23, 2001 02:50 PM
1 comment, last by Vlion 23 years, 8 months ago
OK. I`ve run into some peculiar probs with this program I`m trying to create a program that pulls the determinant of ut of a 2x2 matrix. Simple, yes ? I have commented the probs.

struct MAT22
{
	unsigned char M[2][2];   //It wont work save with chars  Why ?

};
//This routine works fairly well.
int det22(MAT22 mat22)
{
	char	ret, temp, temp2;
	temp = mat22.M[1][1] * mat22.M[2][2];
	temp2 = mat22.M[1][2] * mat22.M[2][1];
	ret = temp - temp2;

	return ret;
}
void main()
{
	MAT22 mat22;
//This is strange. Only mat22.M[1][1] gets assigned
//The other assigning code is dysfunctional and stays at the original garbage values. Again, why ?
	mat22.M[1][1] = 8;
	mat22.M[1][2] = 7;
	mat22.M[2][1] = 2;
	mat22.M[2][2] = 1;
	//	cout << det22(mat22);
}
 
I`ve spent time in the debugger and heres what I`ve found. Using any other kind of data than a char or variant I come up with a access violation in the exit program routines. I have no CLUE why the assigning code is dysfunctional, it shos up in the debugger. Thanx, ~V''lion I came, I saw, I got programmers block. ~V''''lion
~V'lionBugle4d
Well, first off, C/C++ is a 0 index based language, not a 1 index based language, so if you create an array with 2 elements, you access them with 0 and 1.

G''luck,
-Alamar
Advertisement
*groans*
That works....idiot that I am. :-/
Thank you.Now I have to work out the problem with the MAT22 data type
~V''lion

I came, I saw, I got programmers block.
~V''''lion
~V'lionBugle4d

This topic is closed to new replies.

Advertisement